コード例 #1
0
 def exportPbrShaderItem(self):
     item = FileItem('def Shader', 'pbr')
     item.addItem('uniform token', 'info:id', '"UsdPreviewSurface"')
     for input in self.inputs.values():
         item.append(input.exportShaderInputItem(self))
     item.addItem('token', 'outputs:displacement')
     item.addItem('token', 'outputs:surface')
     return item
コード例 #2
0
 def exportMatrixTimeSamples(self):
     item = FileItem('matrix4d', 'xformOp:transform:transforms.timeSamples')
     start = self.scene.startFrame
     end = self.scene.endFrame
     for frame in range(start, end + 1):
         self.scene.context.scene.frame_set(frame)
         item.addTimeSample(frame, self.getTransform())
     self.scene.context.scene.frame_set(self.scene.curFrame)
     return item
コード例 #3
0
 def exportAnimationItems(self):
     items = []
     if self.armatueCopy != None and self.scene.animated:
         self.armatueCopy.data.pose_position = 'POSE'
         tokens = get_joint_tokens(self.armatueCopy)
         item = FileItem('def SkelAnimation', 'Animation')
         item.addItem('uniform token[]', 'joints', tokens)
         item.items += self.exportArmatureAnimationItems(self.armatueCopy)
         items.append(item)
     return items
コード例 #4
0
 def exportShaderInputItem(self, material):
     if self.image != None and self.uvMap != None:
         path = '<' + material.getPath(
         ) + '/' + self.name + '_map.outputs:rgb>'
         if self.type == 'float':
             path = '<' + material.getPath(
             ) + '/' + self.name + '_map.outputs:r>'
         return FileItem(self.type, 'inputs:' + self.name + '.connect',
                         path)
     return FileItem(self.type, 'inputs:' + self.name, self.value)
コード例 #5
0
 def exportMeshUvItems(self, material):
     mesh = self.objectCopy.data
     items = []
     for layer in mesh.uv_layers:
         indices, uvs = export_mesh_uvs(mesh, layer, material)
         name = layer.name.replace('.', '_')
         items.append(
             FileItem('int[]', 'primvars:' + name + ':indices', indices))
         items.append(FileItem('texCoord2f[]', 'primvars:' + name, uvs))
         items[-1].properties['interpolation'] = '"faceVarying"'
     return items
コード例 #6
0
 def exportPrimvarItems(self):
     items = []
     uvMaps = self.getUVMaps()
     for map in uvMaps:
         path = '<' + self.getPath(
         ) + '.inputs:frame:stPrimvar_' + map + '>'
         item = FileItem('def Shader', 'primvar_' + map)
         item.addItem('uniform token', 'info:id',
                      '"UsdPrimvarReader_float2"')
         item.addItem('float2', 'inputs:default', (0.0, 0.0))
         item.addItem('token', 'inputs:varname.connect', path)
         item.addItem('float2', 'outputs:result')
         items.append(item)
     return items
コード例 #7
0
 def exportPrimvarTokens(self):
     items = []
     uvMaps = self.getUVMaps()
     for map in uvMaps:
         items.append(
             FileItem('token', 'inputs:frame:stPrimvar_' + map,
                      '"' + map + '"'))
     return items
コード例 #8
0
 def exportItem(self):
     item = FileItem('def Material', self.name)
     item.items += self.exportPrimvarTokens()
     item.addItem('token', 'outputs:displacement.connect',
                  '<' + self.getPath() + '/pbr.outputs:displacement>')
     item.addItem('token', 'outputs:surface.connect',
                  '<' + self.getPath() + '/pbr.outputs:surface>')
     item.append(self.exportPbrShaderItem())
     item.items += self.exportPrimvarItems()
     item.items += self.exportInputItems()
     return item
コード例 #9
0
 def exportJointItems(self, material):
     mesh = self.objectCopy.data
     items = []
     if self.armatueCopy != None and self.scene.animated:
         indices, weights, size = export_mesh_weights(
             self.objectCopy, material)
         items.append(
             FileItem('int[]', 'primvars:skel:jointIndices', indices))
         items[-1].properties['elementSize'] = size
         items[-1].properties['interpolation'] = '"vertex"'
         items.append(
             FileItem('float[]', 'primvars:skel:jointWeights', weights))
         items[-1].properties['elementSize'] = size
         items[-1].properties['interpolation'] = '"vertex"'
         animation = '<' + self.getPath() + '/Animation>'
         items.append(
             FileItem('prepend rel', 'skel:animationSource', animation))
         skeleton = '<' + self.getPath() + '/' + self.armature.name.replace(
             '.', '_') + '>'
         items.append(FileItem('prepend rel', 'skel:skeleton', skeleton))
     return items
コード例 #10
0
 def exportSkeletonItems(self):
     items = []
     if self.armatueCopy != None and self.scene.animated:
         tokens = get_joint_tokens(self.armatueCopy)
         bind = get_bind_transforms(self.armatueCopy)
         rest = get_rest_transforms(self.armatueCopy)
         item = FileItem('def Skeleton',
                         self.armature.name.replace('.', '_'))
         item.addItem('uniform token[]', 'joints', tokens)
         item.addItem('uniform matrix4d[]', 'bindTransforms', bind)
         item.addItem('uniform matrix4d[]', 'restTransforms', rest)
         items.append(item)
     return items
コード例 #11
0
    def exportItem(self):
        item = FileItem('def Xform', self.name)
        if self.armatueCopy != None and self.scene.animated:
            item = FileItem('def SkelRoot', self.name)
        else:
            if self.scene.animated and self.object.animation_data != None:
                item.append(self.exportMatrixTimeSamples())
                item.addItem('uniform token[]', 'xformOpOrder',
                             ['"xformOp:transform:transforms"'])
            else:
                item.addItem('custom matrix4d', 'xformOp:transform',
                             self.getTransform())
                item.addItem('uniform token[]', 'xformOpOrder',
                             ['"xformOp:transform"'])

        # Add Meshes if Mesh Object
        if self.type == 'MESH':
            item.items += self.exportMeshItems()
            item.items += self.exportMaterialItems()
            item.items += self.exportSkeletonItems()
            item.items += self.exportAnimationItems()

        # Add Any Children
        for child in self.children:
            item.append(child.exportItem())
        return item
コード例 #12
0
 def exportArmatureAnimationItems(self, armature):
     rotationItem = FileItem('quatf[]', 'rotations.timeSamples')
     scaleItem = FileItem('half3[]', 'scales.timeSamples')
     translationItem = FileItem('float3[]', 'translations.timeSamples')
     start = self.scene.startFrame
     end = self.scene.endFrame
     select_object(armature)
     armature.data.pose_position = 'POSE'
     for frame in range(start, end + 1):
         self.scene.context.scene.frame_set(frame)
         self.scene.context.scene.update()
         rotations = []
         scales = []
         locations = []
         for bone in armature.data.bones:
             bone = armature.pose.bones[bone.name]
             scale = bone.scale.copy()
             location = bone.location.copy()
             rotation = bone.bone.matrix.to_quaternion(
             ) @ bone.rotation_quaternion
             if bone.parent != None:
                 if bone.bone.use_connect:
                     location = mathutils.Vector((0, bone.parent.length, 0))
                 else:
                     location += mathutils.Vector(
                         (0, bone.parent.length, 0))
             else:
                 scale *= self.scene.scale
                 location *= self.scene.scale
                 rotation = bone.rotation_quaternion
             rotations.append(rotation[:])
             scales.append(scale[:])
             locations.append(location[:])
         rotationItem.addTimeSample(frame, rotations)
         scaleItem.addTimeSample(frame, scales)
         translationItem.addTimeSample(frame, locations)
     self.scene.context.scene.frame_set(self.scene.curFrame)
     self.scene.context.scene.update()
     bpy.ops.object.mode_set(mode='OBJECT')
     return [rotationItem, scaleItem, translationItem]
コード例 #13
0
    def exportMeshItem(self, material=-1):
        mesh = self.objectCopy.data
        name = self.object.data.name.replace('.', '_')
        if material >= 0:
            name += '_' + self.materials[material].name
        item = FileItem('def Mesh', name)

        extent = object_extents(self.objectCopy, self.scene.scale)
        item.addItem('float3[]', 'extent', extent)

        vertexCounts = mesh_vertex_counts(mesh, material)
        item.addItem('int[]', 'faceVertexCounts', vertexCounts)

        indices, points = export_mesh_vertices(mesh, material)
        item.addItem('int[]', 'faceVertexIndices', indices)
        item.addItem('point3f[]', 'points', points)

        if material >= 0:
            path = self.materials[material].getPath()
            item.addItem('rel', 'material:binding', '<' + path + '>')

        indices, normals = export_mesh_normals(mesh, material)
        item.addItem('int[]', 'primvars:normals:indices', indices)
        item.addItem('normal3f[]', 'primvars:normals', normals)
        item.items[-1].properties['interpolation'] = '"faceVarying"'

        item.items += self.exportMeshUvItems(material)
        item.items += self.exportJointItems(material)
        item.addItem('uniform token', 'subdivisionScheme', '"none"')
        return item
コード例 #14
0
 def exportShaderItem(self, material):
     if self.image != None and self.uvMap != None:
         v = self.value
         default = (v, v, v, 1.0) if self.type == 'float' else v + (1.0, )
         path = '</Materials/' + material + '/primvar_' + self.uvMap + '.outputs:result>'
         item = FileItem('def Shader', self.name + '_map')
         item.addItem('uniform token', 'info:id', '"UsdUVTexture"')
         item.addItem('float4', 'inputs:default', default)
         item.addItem('asset', 'inputs:file', '@' + self.image + '@')
         item.addItem('float2', 'inputs:st.connect', path)
         item.addItem('token', 'inputs:wrapS', '"repeat"')
         item.addItem('token', 'inputs:wrapT', '"repeat"')
         item.addItem('float3', 'outputs:rgb')
         return item
     return None