DNA Calib 1.1
Project brief
Functions
demo Namespace Reference

Functions

def createDNA (path)
 
def loadDNA (path)
 
def printDNASummary (dnaReader)
 
def main ()
 
def saveDNA (reader, path)
 
def buildCommandList ()
 
def calibrateDNA (inputPath, outputPath)
 

Function Documentation

◆ buildCommandList()

def demo.buildCommandList ( )
30 # Abstraction to collect all commands into a sequence, and run them with only one invocation
31 commands = dnac.CommandSequence()
32
33 print("Creating a sequence of commands...")
34 # Instantiate command with parameters: scale-factor = 2 , origin-xyz = (0, 120, 0)
35 scaleByTwo = dnac.ScaleCommand(2.0, [0.0, 120.0, 0.0])
36 # Alternatively a command can be instantiated empty, and populated with parameters later, e.g.:
37 # scaleByTwo = dnac.ScaleCommand()
38 # scaleByTwo.setScale(2.0)
39 # scaleByTwo.setOrigin([0.0, 120.0, 0.0])
40 commands.add(scaleByTwo)
41
42 print("Added command to scale dna")
43 # Rename by joint index (faster)
44 commands.add(dnac.RenameJointCommand(10, "NewJointA"))
45
46 # Rename by matching joint name (slower)
47 commands.add(dnac.RenameJointCommand("OldJointB", "NewJointB"))
48
49 print("Added command to rename joint")
50 # Interpolate blend shape target deltas between original DNA and below specified deltas
51 # ¯\_(ツ)_/¯
52 # Deltas in [[x, y, z], [x, y, z], [x, y, z]] format
53 blendShapeTargetDeltas = [[0.0, 0.0, 2.0], [0.0, -1.0, 4.0], [3.0, -3.0, 8.0]]
54 # Weights for interpolation between original deltas and above defined deltas
55 # 1.0 == take the new value completely, 0.0 means keep the old value
56 # Format: [Delta-0-Mask, Delta-1-Mask, Delta-2-Mask]
57 masks = [1.0, 0.0, 0.5]
58 setBlendShapesM0B0 = dnac.SetBlendShapeTargetDeltasCommand(0, # mesh index
59 0, # blend shape target index
60 blendShapeTargetDeltas,
61 masks,
62 dnac.VectorOperation_Interpolate)
63 commands.add(setBlendShapesM0B0)
64 print("Added command to change blend shape target deltas")
65
66 # Add vertex position deltas onto existing vertex positions
67 # Note the alternative data format, instead of using nested lists, separate all X, Y, Z
68 # components into distinct lists (might also be faster)
69 positionXs = [1.0, -4.5, 7.2]
70 positionYs = [2.0, -5.5, -8.3]
71 positionZs = [3.0, -6.5, 9.7]
72 # Weights to be multiplied with the above specified delta positions, before adding
73 # them onto the original data
74 # Format: [Delta-0-Weight, Delta-1-Weight, Delta-2-Weight]
75 masks = [1.0, 0.2, 0.4]
76 setVerticesM0 = dnac.SetVertexPositionsCommand(0, # mesh index
77 positionXs,
78 positionYs,
79 positionZs,
80 masks,
81 dnac.VectorOperation_Add)
82 commands.add(setVerticesM0)
83 print("Added command to change vertex positions")
84
85 return commands
86
87
CommandSequence is used to run a sequence of commands on the same DNA.
Definition: CommandSequence.h:20
RenameJointCommand is used to rename a joint.
Definition: RenameJointCommand.h:18
ScaleCommand is used to scale neutral joints, vertex positions and joint and blendshape deltas by a f...
Definition: ScaleCommand.h:18
SetBlendShapeTargetDeltasCommand is used to change blend shape target deltas.
Definition: SetBlendShapeTargetDeltasCommand.h:19
SetVertexPositionsCommand is used to change vertex positions values.
Definition: SetVertexPositionsCommand.h:19
def buildCommandList()
Definition: alib/python3/examples/demo.py:29

Referenced by calibrateDNA().

◆ calibrateDNA()

def demo.calibrateDNA (   inputPath,
  outputPath 
)
88def calibrateDNA(inputPath, outputPath):
89 dna = loadDNA(inputPath)
90
91 # Copies DNA contents and will serve as input/output parameter to commands
92 calibrated = dnac.DNACalibDNAReader(dna)
93
94 commands = buildCommandList()
95
96 print("Running command sequence...")
97 # Modifies calibrated DNA in-place
98 commands.run(calibrated)
99
100 print("Saving DNA...")
101 saveDNA(calibrated, outputPath)
102
103 print("Done.")
104
Definition: DNACalibDNAReader.h:12
def calibrateDNA(inputPath, outputPath)
Definition: alib/python3/examples/demo.py:88
def saveDNA(reader, path)
Definition: alib/python3/examples/demo.py:18
def loadDNA(path)
Definition: python3/examples/demo.py:26

References buildCommandList(), calibrateDNA(), loadDNA(), main(), and saveDNA().

Referenced by calibrateDNA().

◆ createDNA()

def demo.createDNA (   path)
7def createDNA(path):
8 stream = dna.FileStream(path, dna.FileStream.AccessMode_Write, dna.FileStream.OpenMode_Binary)
9 writer = dna.BinaryStreamWriter(stream)
10
11 writer.setName("rig name")
12 writer.setLODCount(4)
13 writer.setJointName(0, "spine")
14 writer.setJointName(1, "neck")
15
16 writer.setMeshName(0, "head")
17 writer.setVertexPositions(0, [[0.0, 0.5, 0.3], [1.0, 3.0, -8.0]])
18 writer.setVertexTextureCoordinates(0, [[0.25, 0.55], [1.5, 3.6]])
19
20 writer.write()
21 if not dna.Status.isOk():
22 status = dna.Status.get()
23 raise RuntimeError("Error saving DNA: {}".format(status.message))
24
25
Definition: BinaryStreamWriter.h:11
Standard file stream.
Definition: FileStream.h:13
def createDNA(path)
Definition: python3/examples/demo.py:7

Referenced by main().

◆ loadDNA()

def demo.loadDNA (   path)
26def loadDNA(path):
27 stream = dna.FileStream(path, dna.FileStream.AccessMode_Read, dna.FileStream.OpenMode_Binary)
28 reader = dna.BinaryStreamReader(stream, dna.DataLayer_All)
29 reader.read()
30 if not dna.Status.isOk():
31 status = dna.Status.get()
32 raise RuntimeError("Error loading DNA: {}".format(status.message))
33 return reader
34
35
Definition: BinaryStreamReader.h:12

Referenced by calibrateDNA(), and main().

◆ main()

def demo.main ( )
57def main():
58 parser = argparse.ArgumentParser(description="DNA demo")
59 parser.add_argument('dna_path',
60 metavar='dna_path',
61 help='Path where to save the DNA file')
62
63 args = parser.parse_args()
64
65 createDNA(args.dna_path)
66 dnaReader = loadDNA(args.dna_path)
67 printDNASummary(dnaReader)
68
69
def main()
Definition: python3/examples/demo.py:57
def printDNASummary(dnaReader)
Definition: python3/examples/demo.py:36

References createDNA(), loadDNA(), main(), and printDNASummary().

Referenced by calibrateDNA(), and main().

◆ printDNASummary()

def demo.printDNASummary (   dnaReader)
36def printDNASummary(dnaReader):
37 print("Name: {}".format(dnaReader.getName()))
38 print("Joint count: {}".format(dnaReader.getJointCount()))
39 jointNames = ', '.join(dnaReader.getJointName(i) for i in range(dnaReader.getJointCount()))
40 print("Joint names: " + jointNames)
41
42 for meshIdx in range(dnaReader.getMeshCount()):
43 # Get vertices one by one
44 for vtxId in range(dnaReader.getVertexPositionCount(meshIdx)):
45 vtx = dnaReader.getVertexPosition(meshIdx, vtxId)
46 print("Mesh {} - Vertex {} : {}".format(meshIdx, vtxId, vtx))
47 # Get all X / Y / Z coordinates
48 print(dnaReader.getVertexPositionXs(meshIdx))
49 print(dnaReader.getVertexPositionYs(meshIdx))
50 print(dnaReader.getVertexPositionZs(meshIdx))
51
52 for tcIdx in range(dnaReader.getVertexTextureCoordinateCount(meshIdx)):
53 texCoord = dnaReader.getVertexTextureCoordinate(meshIdx, tcIdx)
54 print("Mesh {} - Texture coordinate {} : {}".format(meshIdx, tcIdx, texCoord))
55
56

Referenced by main().

◆ saveDNA()

def demo.saveDNA (   reader,
  path 
)
18def saveDNA(reader, path):
19 stream = dna.FileStream(path, dna.FileStream.AccessMode_Write, dna.FileStream.OpenMode_Binary)
20 writer = dna.BinaryStreamWriter(stream)
21 writer.setFrom(reader)
22 writer.write()
23
24 if not dna.Status.isOk():
25 status = dna.Status.get()
26 raise RuntimeError("Error saving DNA: {}".format(status.message))
27
28

Referenced by calibrateDNA().