DNA Calib 1.1
Project brief
Functions
clear_blend_shapes Namespace Reference

Functions

def loadDNA (path)
 
def saveDNA (reader, path)
 
def validate_geometry (dna)
 
def validate_animation_data (dna)
 
def calibrateDNA (inputPath, outputPath)
 
def main ()
 

Function Documentation

◆ calibrateDNA()

def clear_blend_shapes.calibrateDNA (   inputPath,
  outputPath 
)
52def calibrateDNA(inputPath, outputPath):
53 dna = loadDNA(inputPath)
54
55 # Copies DNA contents and will serve as input/output parameter to command
56 calibrated = dnac.DNACalibDNAReader(dna)
57
58 mesh_count = calibrated.getMeshCount()
59 print("Number of meshes: {}".format(mesh_count))
60
61 for mesh_index in range(mesh_count):
62 bs_tgt_count = calibrated.getBlendShapeTargetCount(mesh_index)
63 print("Number of blendshape targets for mesh {}({}): {}".format(calibrated.getMeshName(mesh_index), mesh_index, bs_tgt_count))
64 for bs_tgt_index in range(bs_tgt_count):
65 bs_tgt_delta_count = calibrated.getBlendShapeTargetDeltaCount(mesh_index, bs_tgt_index)
66 print("Number of blendshape target deltas for mesh {}({}), blend shape target {}: {}".format(calibrated.getMeshName(mesh_index), mesh_index, bs_tgt_index, bs_tgt_delta_count))
67
68 print("Blend shape channel LODs: {}".format(calibrated.getBlendShapeChannelLODs()))
69 print("Blend shape channel input indices: {}".format(calibrated.getBlendShapeChannelInputIndices()))
70 print("Blend shape channel output indices: {}".format(calibrated.getBlendShapeChannelOutputIndices()))
71
72 # Clears all blend shapes
74
75 print("\n\nClearing blend shape data...\n\n")
76 # Modifies calibrated DNA in-place
77 command.run(calibrated)
78
79 validate_geometry(calibrated)
80 validate_animation_data(calibrated)
81
82 print("Number of meshes: {}".format(mesh_count))
83
84 for mesh_index in range(mesh_count):
85 bs_tgt_count = calibrated.getBlendShapeTargetCount(mesh_index)
86 print("Number of blendshape targets for mesh {}({}): {}".format(calibrated.getMeshName(mesh_index), mesh_index, bs_tgt_count))
87 for bs_tgt_index in range(bs_tgt_count):
88 bs_tgt_delta_count = calibrated.getBlendShapeTargetDeltaCount(mesh_index, bs_tgt_index)
89 print("Number of blendshape target deltas for mesh {}({}), blend shape target {}: {}".format(calibrated.getMeshName(mesh_index), mesh_index, bs_tgt_index, bs_tgt_delta_count))
90
91 bs_channel_lods = dna.getBlendShapeChannelLODs()
92 bs_channel_input_indices = dna.getBlendShapeChannelInputIndices()
93 bs_channel_output_indices = dna.getBlendShapeChannelOutputIndices()
94
95 print("Blend shape channel LODs: {}".format(bs_channel_lods))
96 print("Blend shape channel input indices: {}".format(bs_channel_input_indices))
97 print("Blend shape channel output indices: {}".format(bs_channel_output_indices))
98
99 print("\n\nSuccessfully cleared blend shape data.")
100
101 print("Saving DNA...")
102 saveDNA(calibrated, outputPath)
103 print("Done.")
104
ClearBlendShapesCommand is used to clear all blend shapes data from a DNA.
Definition: ClearBlendShapesCommand.h:19
Definition: DNACalibDNAReader.h:12
def saveDNA(reader, path)
Definition: clear_blend_shapes.py:18
def validate_geometry(dna)
Definition: clear_blend_shapes.py:28
def loadDNA(path)
Definition: clear_blend_shapes.py:8
def calibrateDNA(inputPath, outputPath)
Definition: clear_blend_shapes.py:52
def validate_animation_data(dna)
Definition: clear_blend_shapes.py:37

References loadDNA(), saveDNA(), validate_animation_data(), and validate_geometry().

Referenced by main().

◆ loadDNA()

def clear_blend_shapes.loadDNA (   path)
8def loadDNA(path):
9 stream = dna.FileStream(path, dna.FileStream.AccessMode_Read, dna.FileStream.OpenMode_Binary)
10 reader = dna.BinaryStreamReader(stream, dna.DataLayer_All)
11 reader.read()
12 if not dna.Status.isOk():
13 status = dna.Status.get()
14 raise RuntimeError("Error loading DNA: {}".format(status.message))
15 return reader
16
17
Definition: BinaryStreamReader.h:12
Standard file stream.
Definition: FileStream.h:13

Referenced by calibrateDNA().

◆ main()

def clear_blend_shapes.main ( )
105def main():
106 parser = argparse.ArgumentParser(description="DNACalib clear blend shapes example")
107 parser.add_argument('input_dna',
108 metavar='input-dna',
109 help='Path to DNA file to load')
110 parser.add_argument('output_dna',
111 metavar='output-dna',
112 help='Path where to save modified DNA file')
113
114 args = parser.parse_args()
115
116 calibrateDNA(args.input_dna, args.output_dna)
117
118
def main()
Definition: clear_blend_shapes.py:105

References calibrateDNA(), and main().

Referenced by main().

◆ saveDNA()

def clear_blend_shapes.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
Definition: BinaryStreamWriter.h:11

Referenced by calibrateDNA().

◆ validate_animation_data()

def clear_blend_shapes.validate_animation_data (   dna)
38 bs_channel_lods = dna.getBlendShapeChannelLODs()
39 bs_channel_input_indices = dna.getBlendShapeChannelInputIndices()
40 bs_channel_output_indices = dna.getBlendShapeChannelOutputIndices()
41
42 if len(bs_channel_lods) != dna.getLODCount():
43 raise RuntimeError("Blend shape animation data not removed properly! Number of blend shape LODs does not match LOD count!")
44
45 for lod in bs_channel_lods:
46 if lod != 0:
47 raise RuntimeError("Blend shape animation data not removed properly!")
48
49 if (len(bs_channel_input_indices) != 0) or (len(bs_channel_output_indices) != 0):
50 raise RuntimeError("Blend shape animation data not removed properly!")
51

Referenced by calibrateDNA().

◆ validate_geometry()

def clear_blend_shapes.validate_geometry (   dna)
28def validate_geometry(dna):
29 mesh_count = dna.getMeshCount()
30 for mesh_index in range(mesh_count):
31 bs_tgt_count = dna.getBlendShapeTargetCount(mesh_index)
32 for bs_tgt_index in range(bs_tgt_count):
33 bs_tgt_delta_count = dna.getBlendShapeTargetDeltaCount(mesh_index, bs_tgt_index)
34 if bs_tgt_delta_count != 0:
35 raise RuntimeError("Blend shape target deltas not removed properly!")
36

Referenced by calibrateDNA().