def writeTexture(fp, filepath, channel, config): if not filepath: return filepath = config.copyTextureToNewLocation(filepath) texname = getTextureName(filepath) relpath = getRelativePath(filepath) vid,vkey = getId("Video::%s" % texname) tid,tkey = getId("Texture::%s" % texname) properties_vid = [ ("Path", "p_string_url", filepath) ] properties_tex = [ ("MHName", "p_string", tkey, False, True) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_texture_file_element(elem, tkey, tid, vkey, vid, filepath, relpath, properties_tex, properties_vid) return import fbx_utils fp.write( ' Video: %d, "%s", "Clip" {' % (vid, vkey) + """ Type: "Clip" Properties70: { """ + fbx_utils.get_ascii_properties(properties_vid, indent=3) + """ } UseMipMap: 0 Filename: "%s\"""" % filepath + """ RelativeFilename: "%s\"""" % relpath + """ } """) fp.write( ' Texture: %d, "%s", "" {' % (tid, tkey) + """ Type: "TextureVideoClip" Version: 202 TextureName: "%s\"""" % tkey + """ Properties70: { """ + fbx_utils.get_ascii_properties(properties_tex, indent=3) + """ } Media: "%s\"""" % vkey + """ Filename: "%s\"""" % filepath + """ RelativeFilename: "%s\"""" % relpath + """ ModelUVTranslation: 0,0 ModelUVScaling: 1,1 Texture_Alpha_Source: "None" Cropping: 0,0,0,0 } """)
def writeTexture(fp, filepath, channel, config): if not filepath: return filepath = config.copyTextureToNewLocation(filepath) texname = getTextureName(filepath) relpath = getRelativePath(filepath) vid, vkey = getId("Video::%s" % texname) tid, tkey = getId("Texture::%s" % texname) properties_vid = [("Path", "p_string_url", filepath)] properties_tex = [("MHName", "p_string", tkey, False, True)] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_texture_file_element(elem, tkey, tid, vkey, vid, filepath, relpath, properties_tex, properties_vid) return import fbx_utils fp.write(' Video: %d, "%s", "Clip" {' % (vid, vkey) + """ Type: "Clip" Properties70: { """ + fbx_utils.get_ascii_properties(properties_vid, indent=3) + """ } UseMipMap: 0 Filename: "%s\"""" % filepath + """ RelativeFilename: "%s\"""" % relpath + """ } """) fp.write(' Texture: %d, "%s", "" {' % (tid, tkey) + """ Type: "TextureVideoClip" Version: 202 TextureName: "%s\"""" % tkey + """ Properties70: { """ + fbx_utils.get_ascii_properties(properties_tex, indent=3) + """ } Media: "%s\"""" % vkey + """ Filename: "%s\"""" % filepath + """ RelativeFilename: "%s\"""" % relpath + """ ModelUVTranslation: 0,0 ModelUVScaling: 1,1 Texture_Alpha_Source: "None" Cropping: 0,0,0,0 } """)
def writeMaterial(fp, mesh, config): id,key = getId("Material::"+mesh.name) mat = mesh.material properties = [ ("DiffuseColor", "p_color", mat.diffuseColor.asTuple(), b"A"), ("Diffuse", "p_vector_3d", mat.diffuseColor.asTuple(), b"A"), ("SpecularColor", "p_color", mat.specularColor.asTuple(), b"A"), ("Specular", "p_vector_3d", mat.specularColor.asTuple(), b"A"), ("Shininess", "p_double", mat.shininess, b"A"), ("Reflectivity", "p_double", 0, b"A"), ("Emissive", "p_vector_3d", mat.emissiveColor.asTuple(), b"A"), ("Ambient", "p_vector_3d", mat.ambientColor.asTuple(), b"A"), ("TransparencyFactor", "p_number", mat.transparencyMapIntensity, True, b"A"), ("Opacity", "p_double", mat.opacity, b"A") ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_material(elem, key, id, properties) return import fbx_utils fp.write( ' Material: %d, "%s", "" {' % (id, key) + """ Version: 102 ShadingModel: "phong" MultiLayer: 0 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } } """)
def writeObjectDefs(fp, meshes, nShapes, config): nMeshes = len(meshes) properties = [ ("Color", "p_color_rgb", [0.8,0.8,0.8]), ("BBoxMin", "p_vector_3d", [0,0,0]), ("BBoxMax", "p_vector_3d", [0,0,0]), ("Primary Visibility", "p_bool", True), ("Casts Shadows", "p_bool", True), ("Receive Shadows", "p_bool", True) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "Geometry", (nMeshes + nShapes), "FbxMesh", properties) return import fbx_utils fp.write( ' ObjectType: "Geometry" {\n' + ' Count: %d' % (nMeshes + nShapes) + """ PropertyTemplate: "FbxMesh" { Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=4) + """ } } } """)
def writeMeshProp(fp, mesh, config): id,key = getId("Model::%sMesh" % mesh.name) properties = [ ("RotationActive", "p_bool", 1), ("InheritType", "p_enum", 1), ("ScalingMax", "p_vector_3d", [0,0,0]), ("DefaultAttributeIndex", "p_integer", 0), ("MHName", "p_string", mesh.name, False, True) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_model_element(elem, key, id, properties) return import fbx_utils fp.write( ' Model: %d, "%s", "Mesh" {' % (id, key) + """ Version: 232 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=4) + """ } Shading: Y Culling: "CullingOff" } """)
def writeDeformer(fp, name, config): id,key = getId("Deformer::%s" % name) properties = [ ("MHName", "p_string", "%sSkin" % name, False, True) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_deformer(elem, key, id, properties) return import fbx_utils fp.write( ' Deformer: %d, "%s", "Skin" {' % (id, key) + """ Version: 101 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } Link_DeformAcuracy: 50 } """)
def writeMeshProp(fp, mesh, config): id, key = getId("Model::%sMesh" % mesh.name) properties = [("RotationActive", "p_bool", 1), ("InheritType", "p_enum", 1), ("ScalingMax", "p_vector_3d", [0, 0, 0]), ("DefaultAttributeIndex", "p_integer", 0), ("MHName", "p_string", mesh.name, False, True)] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_model_element(elem, key, id, properties) return import fbx_utils fp.write(' Model: %d, "%s", "Mesh" {' % (id, key) + """ Version: 232 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=4) + """ } Shading: Y Culling: "CullingOff" } """)
def writeMaterial(fp, mesh, config): id, key = getId("Material::" + mesh.name) mat = mesh.material properties = [ ("TransparentColor", "p_color", tuple(3 * [1.0 - mat.opacity]), True), ("TransparencyFactor", "p_number", mat.transparencyMapIntensity, True), #("ShininessExponent", "p_number", mat.shininess, True), #("EmissiveColor", "p_vector_3d", mat.emissiveColor.asTuple()), #("AmbientColor", "p_vector_3d", mat.ambientColor.asTuple()), ("DiffuseColor", "p_vector_3d", mat.diffuseColor.asTuple()), ("DiffuseFactor", "p_number", 1.0, True), ("SpecularColor", "p_vector_3d", mat.specularColor.asTuple()), ("SpecularFactor", "p_number", mat.specularMapIntensity, True), ("Shininess", "p_double", mat.shininess), ("Reflectivity", "p_double", 0) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_deformer(elem, key, id, properties) return import fbx_utils fp.write(' Material: %d, "%s", "" {' % (id, key) + """ Version: 102 ShadingModel: "phong" MultiLayer: 0 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } } """)
def writeNodeAttributeProp(fp, bone, config): id, key = getId("NodeAttribute::%s" % bone.name) properties = [("Size", "p_double", 1), ("LimbLength", "p_double", bone.length)] # TODO what to do with "H" flag? if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, "Objects") fbx_binary.fbx_data_skeleton_bone_node(elem, key, id, properties) return import fbx_utils fp.write( ' NodeAttribute: %d, "%s", "LimbNode" {' % (id, key) + """ Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } TypeFlags: "Skeleton" } """ )
def writeNodeProp(fp, skel, config): id,key = getId("Model::%s" % skel.name) properties = [ ("RotationActive", "p_bool", 1), ("InheritType", "p_enum", 1), ("ScalingMax", "p_vector_3d", [0,0,0]), ("MHName", "p_string", skel.name, False, True) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_skeleton_model(elem, key, id, properties) return import fbx_utils fp.write( ' Model: %d, "%s", "Null" {' % (id, key) + """ Version: 232 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } Shading: Y Culling: "CullingOff" } """)
def writeObjectDefs(fp, meshes, nShapes, config): nMeshes = len(meshes) properties = [("Color", "p_color_rgb", [0.8, 0.8, 0.8]), ("BBoxMin", "p_vector_3d", [0, 0, 0]), ("BBoxMax", "p_vector_3d", [0, 0, 0]), ("Primary Visibility", "p_bool", True), ("Casts Shadows", "p_bool", True), ("Receive Shadows", "p_bool", True)] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "Geometry", (nMeshes + nShapes), "FbxMesh", properties) return import fbx_utils fp.write(' ObjectType: "Geometry" {\n' + ' Count: %d' % (nMeshes + nShapes) + """ PropertyTemplate: "FbxMesh" { Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=4) + """ } } } """)
def writeBoneProp(fp, bone, config): import fbx_utils id, key = getId("Model::%s" % bone.name) mat = bone.getRelativeMatrix(config.meshOrientation, config.localBoneAxis, config.offset) trans = mat[:3, 3] e = tm.euler_from_matrix(mat, axes="sxyz") properties = [ ("RotationActive", "p_bool", 1), ("InheritType", "p_enum", 1), ("ScalingMax", "p_vector_3d", [0, 0, 0]), ("DefaultAttributeIndex", "p_integer", 0), ("Lcl Translation", "p_lcl_translation", list(trans), True), ("Lcl Rotation", "p_lcl_rotation", [e[0] * R, e[1] * R, e[2] * R], True), ("Lcl Scaling", "p_lcl_scaling", [1, 1, 1], True), ("MHName", "p_string", bone.name, False, True), ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, "Objects") fbx_binary.fbx_data_skeleton_bone_model(elem, key, id, properties) return fp.write( ' Model: %d, "%s", "LimbNode" {' % (id, key) + """ Version: 232 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } Shading: Y Culling: "CullingOff" } """ )
def writeNodeAttributeProp(fp, bone, config): id, key = getId("NodeAttribute::%s" % bone.name) properties = [ ("Size", "p_double", 1), ("LimbLength", "p_double", 1) # TODO what to do with "H" flag? ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_skeleton_bone_node(elem, key, id, properties) return import fbx_utils fp.write(' NodeAttribute: %d, "%s", "LimbNode" {' % (id, key) + """ Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } TypeFlags: "Skeleton" }""")
def writeBoneProp(fp, bone, config): import fbx_utils id, key = getId("Model::%s" % bone.name) mat = bone.getRelativeMatrix(config.meshOrientation, config.localBoneAxis, config.offset) trans = mat[:3, 3] e = tm.euler_from_matrix(mat, axes='sxyz') properties = [ ("RotationActive", "p_bool", 1), ("InheritType", "p_enum", 1), ("ScalingMax", "p_vector_3d", [0, 0, 0]), ("DefaultAttributeIndex", "p_integer", 0), ("Lcl Translation", "p_lcl_translation", list(trans), True), ("Lcl Rotation", "p_lcl_rotation", [e[0] * R, e[1] * R, e[2] * R], True), ("Lcl Scaling", "p_lcl_scaling", [1, 1, 1], True), ("MHName", "p_string", bone.name, False, True), ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_skeleton_bone_model(elem, key, id, properties) return fp.write(' Model: %d, "%s", "LimbNode" {' % (id, key) + """ Version: 232 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } Shading: Y Culling: "CullingOff" } """)
def writeNodeProp(fp, skel, config): id, key = getId("Model::%s" % skel.name) properties = [("RotationActive", "p_bool", 1), ("InheritType", "p_enum", 1), ("ScalingMax", "p_vector_3d", [0, 0, 0]), ("MHName", "p_string", skel.name, False, True)] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_skeleton_model(elem, key, id, properties) return import fbx_utils fp.write(' Model: %d, "%s", "Null" {' % (id, key) + """ Version: 232 Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } Shading: Y Culling: "CullingOff" } """)
def writeObjectDefs(fp, meshes, config): nMaterials, nTextures, nImages = getObjectNumbers(meshes) properties_mat = [("ShadingModel", "p_string", "Phong"), ("MultiLayer", "p_bool", 0), ("EmissiveColor", "p_color", [0, 0, 0], True), ("EmissiveFactor", "p_number", 1, True), ("AmbientColor", "p_color", [0.2, 0.2, 0.2], True), ("AmbientFactor", "p_number", 1, True), ("DiffuseColor", "p_color", [0.8, 0.8, 0.8], True), ("DiffuseFactor", "p_number", 1, True), ("Bump", "p_vector_3d", [0, 0, 0]), ("NormalMap", "p_vector_3d", [0, 0, 0]), ("BumpFactor", "p_double", 1), ("TransparentColor", "p_color", [0, 0, 0], True), ("TransparencyFactor", "p_number", 0, True), ("DisplacementColor", "p_color_rgb", [0, 0, 0]), ("DisplacementFactor", "p_double", 1), ("VectorDisplacementColor", "p_color_rgb", [0, 0, 0]), ("VectorDisplacementFactor", "p_double", 1), ("SpecularColor", "p_color", [0.2, 0.2, 0.2], True), ("SpecularFactor", "p_number", 1, True), ("ShininessExponent", "p_number", 20, True), ("ReflectionColor", "p_color", [0, 0, 0], True), ("ReflectionFactor", "p_number", 1, True)] properties_tex = [("TextureTypeUse", "p_enum", 0), ("Texture alpha", "p_number", 1, True), ("CurrentMappingType", "p_enum", 0), ("WrapModeU", "p_enum", 0), ("WrapModeV", "p_enum", 0), ("UVSwap", "p_bool", 0), ("PremultiplyAlpha", "p_bool", 1), ("Translation", "p_vector", [0, 0, 0], True), ("Rotation", "p_vector", [0, 0, 0], True), ("Scaling", "p_vector", [1, 1, 1], True), ("TextureRotationPivot", "p_vector_3d", [0, 0, 0]), ("TextureScalingPivot", "p_vector_3d", [0, 0, 0]), ("CurrentTextureBlendMode", "p_enum", 1), ("UVSet", "p_string", "default"), ("UseMaterial", "p_bool", 0), ("UseMipMap", "p_bool", 0)] properties_vid = [("ImageSequence", "p_bool", 0), ("ImageSequenceOffset", "p_integer", 0), ("FrameRate", "p_double", 0), ("LastFrame", "p_integer", 0), ("Width", "p_integer", 0), ("Height", "p_integer", 0), ("Path", "p_string_url", ""), ("StartFrame", "p_integer", 0), ("StopFrame", "p_integer", 0), ("PlaySpeed", "p_double", 0), ("Offset", "p_timestamp", 0), ("InterlaceMode", "p_enum", 0), ("FreeRunning", "p_bool", 0), ("Loop", "p_bool", 0), ("AccessMode", "p_enum", 0)] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "Material", nMaterials, None, properties_mat) fbx_binary.fbx_template_generate(elem, "Texture", nTextures, "FbxFileTexture", properties_tex) fbx_binary.fbx_template_generate(elem, "Video", nImages, "FbxVideo", properties_vid) return import fbx_utils fp.write(""" ObjectType: "Material" { """ + ' Count: %d' % (nMaterials) + """ PropertyTemplate: "FbxSurfacePhong" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_mat, indent=4) + """ } } } """) fp.write(""" ObjectType: "Texture" { """ + ' Count: %d' % (nTextures) + """ PropertyTemplate: "FbxFileTexture" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_tex, indent=4) + """ } } } ObjectType: "Video" { """ + ' Count: %d' % (nImages) + """ PropertyTemplate: "FbxVideo" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_vid, indent=4) + """ } } } """)
def writeGeometryProp(fp, mesh, config): id,key = getId("Geometry::%s" % mesh.name) nVerts = len(mesh.coord) nFaces = len(mesh.fvert) coord = mesh.coord + config.offset properties = [ ("MHName", "p_string", "%sMesh" % mesh.name, False, True) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_mesh_element(elem, key, id, properties, coord, mesh.fvert, mesh.vnorm, mesh.texco, mesh.fuvs) return vertString = ",".join( ["%.4f,%.4f,%.4f" % tuple(co) for co in coord] ) if mesh.vertsPerPrimitive == 4: indexString = ",".join( ['%d,%d,%d,%d' % (fv[0],fv[1],fv[2],-1-fv[3]) for fv in mesh.fvert] ) else: indexString = ",".join( ['%d,%d,%d' % (fv[0],fv[1],-1-fv[2]) for fv in mesh.fvert] ) import fbx_utils fp.write( ' Geometry: %d, "%s", "Mesh" {\n' % (id, key) + ' Properties70: {\n' + fbx_utils.get_ascii_properties(properties, indent=4) + '\n' + ' }\n' + ' Vertices: *%d {\n' % (3*nVerts) + ' a: %s\n' % vertString + ' } \n' + ' PolygonVertexIndex: *%d {\n' % (mesh.vertsPerPrimitive*nFaces) + ' a: %s\n' % indexString + ' } \n') # Must use normals for shapekeys nNormals = len(mesh.vnorm) normalString = ",".join( ["%.4f,%.4f,%.4f" % tuple(no) for no in mesh.vnorm] ) if mesh.vertsPerPrimitive == 4: normalIndexString = ",".join( ['%d,%d,%d,%d' % (fv[0],fv[1],fv[2],fv[3]) for fv in mesh.fvert] ) else: normalIndexString = ",".join( ['%d,%d,%d' % (fv[0],fv[1],fv[2]) for fv in mesh.fvert] ) fp.write( ' GeometryVersion: 124\n' + ' LayerElementNormal: 0 {\n' + ' Version: 101\n' + ' Name: "%s_Normal"\n' % mesh.name + ' MappingInformationType: "ByPolygonVertex"\n' + ' ReferenceInformationType: "IndexToDirect"\n' + ' Normals: *%d {\n' % (3*nNormals) + ' a: %s\n' % normalString + ' }\n' + ' NormalsIndex: *%d {\n' % (mesh.vertsPerPrimitive*len(mesh.fvert)) + ' a: %s\n' % normalIndexString + ' } \n') fp.write(' } \n') writeUvs2(fp, mesh) fp.write( """ LayerElementMaterial: 0 { Version: 101 """ + ' Name: "%s_Material"' % mesh.name + """ MappingInformationType: "AllSame" ReferenceInformationType: "IndexToDirect" Materials: *1 { a: 0 } } LayerElementTexture: 0 { MappingInformationType: "ByPolygonVertex" ReferenceInformationType: "IndexToDirect" BlendMode: "Translucent" """ + ' Name: "%s_Texture"' % mesh.name + """ Version: 101 TextureAlpha: 1.0 } Layer: 0 { Version: 100 LayerElement: { Type: "LayerElementUV" TypedIndex: 0 } LayerElement: { Type: "LayerElementNormal" TypedIndex: 0 } LayerElement: { Type: "LayerElementMaterial" TypedIndex: 0 } LayerElement: { Type: "LayerElementTexture" TypedIndex: 0 } } } """)
def writeObjectDefs(fp, action, config): ncurves = len(action.keys()) properties_stack = [ ("Description", "p_string", ""), ("LocalStart", "p_timestamp", 0), ("LocalStop", "p_timestamp", 0), ("ReferenceStart", "p_timestamp", 0), ("ReferenceStop", "p_timestamp", 0) ] properties_layer = [ ("Weight", "p_number", 100, True), ("Mute", "p_bool", 0), ("Solo", "p_bool", 0), ("Lock", "p_bool", 0), ("Color", "p_color_rgb", [0.8,0.8,0.8]), ("BlendMode", "p_enum", 0), ("RotationAccumulationMode", "p_enum", 0), ("ScaleAccumulationMode", "p_enum", 0), ("BlendModeBypass", "p_ulonglong", 0) ] properties_curvenode = [ ("d", "p_compound", "") ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "AnimationStack", 1, "FbxAnimStack", properties_stack) fbx_binary.fbx_template_generate(elem, "AnimationLayer", 1, "FbxAnimLayer", properties_layer) fbx_binary.fbx_template_generate(elem, "AnimationCurveNode", ncurves, "FbxAnimCurveNode", properties_curvenode) fbx_binary.fbx_template_generate(elem, "AnimationCurve", 3*ncurves) return import fbx_utils fp.write( """ ObjectType: "AnimationStack" { Count: 1 PropertyTemplate: "FbxAnimStack" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_stack, indent=4) + """ } } } ObjectType: "AnimationLayer" { Count: 1 PropertyTemplate: "FbxAnimLayer" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_layer, indent=4) + """ } } } ObjectType: "AnimationCurveNode" { """ + ' Count: %d' % ncurves + """ PropertyTemplate: "FbxAnimCurveNode" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_curvenode, indent=4) + """ } } } ObjectType: "AnimationCurve" { """ + ' Count: %d' % (3*ncurves) + """ } """)
def writeObjectDefs(fp, meshes, skel, config): nModels = len(meshes) if skel: nBones = skel.getBoneCount() nModels += nBones + 1 # (name, ptype, value, animatable, custom) properties = [ ("QuaternionInterpolate", "p_enum", 0), ("RotationOffset", "p_vector_3d", [0,0,0]), ("RotationPivot", "p_vector_3d", [0,0,0]), ("ScalingOffset", "p_vector_3d", [0,0,0]), ("ScalingPivot", "p_vector_3d", [0,0,0]), ("TranslationActive", "p_bool", 0), ("TranslationMin", "p_vector_3d", [0,0,0]), ("TranslationMax", "p_vector_3d", [0,0,0]), ("TranslationMinX", "p_bool", 0), ("TranslationMinY", "p_bool", 0), ("TranslationMinZ", "p_bool", 0), ("TranslationMaxX", "p_bool", 0), ("TranslationMaxY", "p_bool", 0), ("TranslationMaxZ", "p_bool", 0), ("RotationOrder", "p_enum", 0), ("RotationSpaceForLimitOnly", "p_bool", 0), ("RotationStiffnessX", "p_double", 0), ("RotationStiffnessY", "p_double", 0), ("RotationStiffnessZ", "p_double", 0), ("AxisLen", "p_double", 10), ("PreRotation", "p_vector_3d", [0,0,0]), ("PostRotation", "p_vector_3d", [0,0,0]), ("RotationActive", "p_bool", 0), ("RotationMin", "p_vector_3d", [0,0,0]), ("RotationMax", "p_vector_3d", [0,0,0]), ("RotationMinX", "p_bool", 0), ("RotationMinY", "p_bool", 0), ("RotationMinZ", "p_bool", 0), ("RotationMaxX", "p_bool", 0), ("RotationMaxY", "p_bool", 0), ("RotationMaxZ", "p_bool", 0), ("InheritType", "p_enum", 0), ("ScalingActive", "p_bool", 0), ("ScalingMin", "p_vector_3d", [0,0,0]), ("ScalingMax", "p_vector_3d", [1,1,1]), ("ScalingMinX", "p_bool", [0]), ("ScalingMinY", "p_bool", [0]), ("ScalingMinZ", "p_bool", [0]), ("ScalingMaxX", "p_bool", [0]), ("ScalingMaxY", "p_bool", 0), ("ScalingMaxZ", "p_bool", 0), ("GeometricTranslation", "p_vector_3d", [0,0,0]), ("GeometricRotation", "p_vector_3d", [0,0,0]), ("GeometricScaling", "p_vector_3d", [1,1,1]), ("MinDampRangeX", "p_double", 0), ("MinDampRangeZ", "p_double", 0), ("MinDampRangeY", "p_double", 0), ("MaxDampRangeX", "p_double", 0), ("MaxDampRangeY", "p_double", 0), ("MaxDampRangeZ", "p_double", 0), ("MinDampStrengthX", "p_double", 0), ("MinDampStrengthY", "p_double", 0), ("MinDampStrengthZ", "p_double", 0), ("MaxDampStrengthX", "p_double", 0), ("MaxDampStrengthY", "p_double", 0), ("MaxDampStrengthZ", "p_double", 0), ("PreferedAngleX", "p_double", 0), ("PreferedAngleY", "p_double", 0), ("PreferedAngleZ", "p_double", 0), ("LookAtProperty", "p_object", None), ("UpVectorProperty", "p_object", None), ("Show", "p_bool", 1), ("NegativePercentShapeSupport", "p_bool", 1), ("DefaultAttributeIndex", "p_integer", -1), ("Freeze", "p_bool", 0), ("LODBox", "p_bool", 0), ("Lcl Translation", "p_lcl_translation", [0,0,0], True), ("Lcl Rotation", "p_lcl_rotation", [0,0,0], True), ("Lcl Scaling", "p_lcl_scaling", [1,1,1], True), ("Visibility", "p_visibility", 1, True), ("Visibility Inheritance", "p_visibility_inheritance", 1) ] skel_properties = [ ("Color", "p_color_rgb", [0.8,0.8,0.8]), ("Size", "p_double", 100), ("LimbLength", "p_double", 1) # TODO this property had special "H" flag, is this required? ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "Model", nModels, "FbxNode", properties) if skel: fbx_binary.fbx_template_generate(elem, "NodeAttribute", nBones, "FbxSkeleton", skel_properties) return import fbx_utils fp.write( """ ObjectType: "Model" { """ + ' Count: %d' % nModels + """ PropertyTemplate: "FbxNode" { Properties70: { """+ fbx_utils.get_ascii_properties(properties, indent=3) + """ } } } """) if skel: fp.write( """ ObjectType: "NodeAttribute" { Count: %d""" % (nBones) + """ PropertyTemplate: "FbxSkeleton" { Properties70: { """ + fbx_utils.get_ascii_properties(skel_properties, indent=3) + """ } } } """)
def writeObjectDefs(fp, meshes, skel, config): nModels = len(meshes) if skel: nBones = skel.getBoneCount() nModels += nBones + 1 # (name, ptype, value, animatable, custom) properties = [("QuaternionInterpolate", "p_enum", 0), ("RotationOffset", "p_vector_3d", [0, 0, 0]), ("RotationPivot", "p_vector_3d", [0, 0, 0]), ("ScalingOffset", "p_vector_3d", [0, 0, 0]), ("ScalingPivot", "p_vector_3d", [0, 0, 0]), ("TranslationActive", "p_bool", 0), ("TranslationMin", "p_vector_3d", [0, 0, 0]), ("TranslationMax", "p_vector_3d", [0, 0, 0]), ("TranslationMinX", "p_bool", 0), ("TranslationMinY", "p_bool", 0), ("TranslationMinZ", "p_bool", 0), ("TranslationMaxX", "p_bool", 0), ("TranslationMaxY", "p_bool", 0), ("TranslationMaxZ", "p_bool", 0), ("RotationOrder", "p_enum", 0), ("RotationSpaceForLimitOnly", "p_bool", 0), ("RotationStiffnessX", "p_double", 0), ("RotationStiffnessY", "p_double", 0), ("RotationStiffnessZ", "p_double", 0), ("AxisLen", "p_double", 10), ("PreRotation", "p_vector_3d", [0, 0, 0]), ("PostRotation", "p_vector_3d", [0, 0, 0]), ("RotationActive", "p_bool", 0), ("RotationMin", "p_vector_3d", [0, 0, 0]), ("RotationMax", "p_vector_3d", [0, 0, 0]), ("RotationMinX", "p_bool", 0), ("RotationMinY", "p_bool", 0), ("RotationMinZ", "p_bool", 0), ("RotationMaxX", "p_bool", 0), ("RotationMaxY", "p_bool", 0), ("RotationMaxZ", "p_bool", 0), ("InheritType", "p_enum", 0), ("ScalingActive", "p_bool", 0), ("ScalingMin", "p_vector_3d", [0, 0, 0]), ("ScalingMax", "p_vector_3d", [1, 1, 1]), ("ScalingMinX", "p_bool", [0]), ("ScalingMinY", "p_bool", [0]), ("ScalingMinZ", "p_bool", [0]), ("ScalingMaxX", "p_bool", [0]), ("ScalingMaxY", "p_bool", 0), ("ScalingMaxZ", "p_bool", 0), ("GeometricTranslation", "p_vector_3d", [0, 0, 0]), ("GeometricRotation", "p_vector_3d", [0, 0, 0]), ("GeometricScaling", "p_vector_3d", [1, 1, 1]), ("MinDampRangeX", "p_double", 0), ("MinDampRangeZ", "p_double", 0), ("MinDampRangeY", "p_double", 0), ("MaxDampRangeX", "p_double", 0), ("MaxDampRangeY", "p_double", 0), ("MaxDampRangeZ", "p_double", 0), ("MinDampStrengthX", "p_double", 0), ("MinDampStrengthY", "p_double", 0), ("MinDampStrengthZ", "p_double", 0), ("MaxDampStrengthX", "p_double", 0), ("MaxDampStrengthY", "p_double", 0), ("MaxDampStrengthZ", "p_double", 0), ("PreferedAngleX", "p_double", 0), ("PreferedAngleY", "p_double", 0), ("PreferedAngleZ", "p_double", 0), ("LookAtProperty", "p_object", None), ("UpVectorProperty", "p_object", None), ("Show", "p_bool", 1), ("NegativePercentShapeSupport", "p_bool", 1), ("DefaultAttributeIndex", "p_integer", -1), ("Freeze", "p_bool", 0), ("LODBox", "p_bool", 0), ("Lcl Translation", "p_lcl_translation", [0, 0, 0], True), ("Lcl Rotation", "p_lcl_rotation", [0, 0, 0], True), ("Lcl Scaling", "p_lcl_scaling", [1, 1, 1], True), ("Visibility", "p_visibility", 1, True), ("Visibility Inheritance", "p_visibility_inheritance", 1)] skel_properties = [ ("Color", "p_color_rgb", [0.8, 0.8, 0.8]), ("Size", "p_double", 100), ("LimbLength", "p_double", 1 ) # TODO this property had special "H" flag, is this required? ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "Model", nModels, "FbxNode", properties) if skel: fbx_binary.fbx_template_generate(elem, "NodeAttribute", nBones, "FbxSkeleton", skel_properties) return import fbx_utils fp.write(""" ObjectType: "Model" { """ + ' Count: %d' % nModels + """ PropertyTemplate: "FbxNode" { Properties70: { """ + fbx_utils.get_ascii_properties(properties, indent=3) + """ } } } """) if skel: fp.write(""" ObjectType: "NodeAttribute" { Count: %d""" % (nBones) + """ PropertyTemplate: "FbxSkeleton" { Properties70: { """ + fbx_utils.get_ascii_properties(skel_properties, indent=3) + """ } } } """)
def writeGeometryProp(fp, mesh, config): id, key = getId("Geometry::%s" % mesh.name) nVerts = len(mesh.coord) nFaces = len(mesh.fvert) coord = mesh.coord + config.offset properties = [("MHName", "p_string", "%sMesh" % mesh.name, False, True)] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Objects') fbx_binary.fbx_data_mesh_element(elem, key, id, properties, coord, mesh.fvert, mesh.vnorm, mesh.texco, mesh.fuvs) return vertString = ",".join(["%.4f,%.4f,%.4f" % tuple(co) for co in coord]) if mesh.vertsPerPrimitive == 4: indexString = ",".join([ '%d,%d,%d,%d' % (fv[0], fv[1], fv[2], -1 - fv[3]) for fv in mesh.fvert ]) else: indexString = ",".join( ['%d,%d,%d' % (fv[0], fv[1], -1 - fv[2]) for fv in mesh.fvert]) import fbx_utils fp.write(' Geometry: %d, "%s", "Mesh" {\n' % (id, key) + ' Properties70: {\n' + fbx_utils.get_ascii_properties(properties, indent=4) + '\n' + ' }\n' + ' Vertices: *%d {\n' % (3 * nVerts) + ' a: %s\n' % vertString + ' } \n' + ' PolygonVertexIndex: *%d {\n' % (mesh.vertsPerPrimitive * nFaces) + ' a: %s\n' % indexString + ' } \n') # Must use normals for shapekeys nNormals = len(mesh.vnorm) normalString = ",".join( ["%.4f,%.4f,%.4f" % tuple(no) for no in mesh.vnorm]) if mesh.vertsPerPrimitive == 4: normalIndexString = ",".join([ '%d,%d,%d,%d' % (fv[0], fv[1], fv[2], fv[3]) for fv in mesh.fvert ]) else: normalIndexString = ",".join( ['%d,%d,%d' % (fv[0], fv[1], fv[2]) for fv in mesh.fvert]) fp.write(' GeometryVersion: 124\n' + ' LayerElementNormal: 0 {\n' + ' Version: 101\n' + ' Name: "%s_Normal"\n' % mesh.name + ' MappingInformationType: "ByPolygonVertex"\n' + ' ReferenceInformationType: "IndexToDirect"\n' + ' Normals: *%d {\n' % (3 * nNormals) + ' a: %s\n' % normalString + ' }\n' + ' NormalsIndex: *%d {\n' % (mesh.vertsPerPrimitive * len(mesh.fvert)) + ' a: %s\n' % normalIndexString + ' } \n') fp.write(' } \n') writeUvs2(fp, mesh) fp.write(""" LayerElementMaterial: 0 { Version: 101 """ + ' Name: "%s_Material"' % mesh.name + """ MappingInformationType: "AllSame" ReferenceInformationType: "IndexToDirect" Materials: *1 { a: 0 } } LayerElementTexture: 0 { MappingInformationType: "ByPolygonVertex" ReferenceInformationType: "IndexToDirect" BlendMode: "Translucent" """ + ' Name: "%s_Texture"' % mesh.name + """ Version: 101 TextureAlpha: 1.0 } Layer: 0 { Version: 100 LayerElement: { Type: "LayerElementUV" TypedIndex: 0 } LayerElement: { Type: "LayerElementNormal" TypedIndex: 0 } LayerElement: { Type: "LayerElementMaterial" TypedIndex: 0 } LayerElement: { Type: "LayerElementTexture" TypedIndex: 0 } } } """)
def writeObjectDefs(fp, meshes, config): nMaterials,nTextures,nImages = getObjectNumbers(meshes) properties_mat = [ ("ShadingModel", "p_string", "Phong"), ("MultiLayer", "p_bool", 0), ("EmissiveColor", "p_color", [0,0,0], True), ("EmissiveFactor", "p_number", 1, True), ("AmbientColor", "p_color", [0.2,0.2,0.2], True), ("AmbientFactor", "p_number", 1, True), ("DiffuseColor", "p_color", [0.8,0.8,0.8], True), ("DiffuseFactor", "p_number", 1, True), ("Bump", "p_vector_3d", [0,0,0]), ("NormalMap", "p_vector_3d", [0,0,0]), ("BumpFactor", "p_double", 1), ("TransparentColor", "p_color", [0,0,0], True), ("TransparencyFactor", "p_number", 0, True), ("DisplacementColor", "p_color_rgb", [0,0,0]), ("DisplacementFactor", "p_double", 1), ("VectorDisplacementColor", "p_color_rgb", [0,0,0]), ("VectorDisplacementFactor", "p_double", 1), ("SpecularColor", "p_color", [0.2,0.2,0.2], True), ("SpecularFactor", "p_number", 1, True), ("ShininessExponent", "p_number", 20, True), ("ReflectionColor", "p_color", [0,0,0], True), ("ReflectionFactor", "p_number", 1, True) ] properties_tex = [ ("TextureTypeUse", "p_enum", 0), ("Texture alpha", "p_number", 1, True), ("CurrentMappingType", "p_enum", 0), ("WrapModeU", "p_enum", 0), ("WrapModeV", "p_enum", 0), ("UVSwap", "p_bool", 0), ("PremultiplyAlpha", "p_bool", 1), ("Translation", "p_vector", [0,0,0], True), ("Rotation", "p_vector", [0,0,0], True), ("Scaling", "p_vector", [1,1,1], True), ("TextureRotationPivot", "p_vector_3d", [0,0,0]), ("TextureScalingPivot", "p_vector_3d", [0,0,0]), ("CurrentTextureBlendMode", "p_enum", 1), ("UVSet", "p_string", "default"), ("UseMaterial", "p_bool", 0), ("UseMipMap", "p_bool", 0) ] properties_vid = [ ("ImageSequence", "p_bool", 0), ("ImageSequenceOffset", "p_integer", 0), ("FrameRate", "p_double", 0), ("LastFrame", "p_integer", 0), ("Width", "p_integer", 0), ("Height", "p_integer", 0), ("Path", "p_string_url", ""), ("StartFrame", "p_integer", 0), ("StopFrame", "p_integer", 0), ("PlaySpeed", "p_double", 0), ("Offset", "p_timestamp", 0), ("InterlaceMode", "p_enum", 0), ("FreeRunning", "p_bool", 0), ("Loop", "p_bool", 0), ("AccessMode", "p_enum", 0) ] if config.binary: from . import fbx_binary elem = fbx_binary.get_child_element(fp, 'Definitions') fbx_binary.fbx_template_generate(elem, "Material", nMaterials, None, properties_mat) fbx_binary.fbx_template_generate(elem, "Texture", nTextures, "FbxFileTexture", properties_tex) fbx_binary.fbx_template_generate(elem, "Video", nImages, "FbxVideo", properties_vid) return import fbx_utils fp.write( """ ObjectType: "Material" { """ + ' Count: %d' % (nMaterials) + """ PropertyTemplate: "FbxSurfacePhong" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_mat, indent=4) + """ } } } """) fp.write( """ ObjectType: "Texture" { """ + ' Count: %d' % (nTextures) + """ PropertyTemplate: "FbxFileTexture" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_tex, indent=4) + """ } } } ObjectType: "Video" { """ + ' Count: %d' % (nImages) + """ PropertyTemplate: "FbxVideo" { Properties70: { """ + fbx_utils.get_ascii_properties(properties_vid, indent=4) + """ } } } """)