예제 #1
0
 public gltfMorphTarget ToGltf(ExportingGltfData data, bool useNormal, bool useSparse)
 {
     return(BlendShapeExporter.Export(data,
                                      m_positions,
                                      useNormal ? m_normals : null,
                                      useSparse));
 }
예제 #2
0
 public gltfMorphTarget ToGltf(glTF gltf, int gltfBuffer, bool useNormal, bool useSparse)
 {
     return(BlendShapeExporter.Export(gltf, gltfBuffer,
                                      m_positions,
                                      useNormal ? m_normals : null,
                                      useSparse));
 }
        static gltfMorphTarget ExportMorphTarget(ExportingGltfData data,
                                                 Mesh mesh, int blendShapeIndex,
                                                 bool useSparseAccessorForMorphTarget,
                                                 bool exportOnlyBlendShapePosition,
                                                 IAxisInverter axisInverter)
        {
            var blendShapeVertices = mesh.vertices;
            var usePosition        = blendShapeVertices != null && blendShapeVertices.Length > 0;

            var blendShapeNormals = mesh.normals;
            var useNormal         = usePosition && blendShapeNormals != null && blendShapeNormals.Length == blendShapeVertices.Length;
            // var useNormal = usePosition && blendShapeNormals != null && blendShapeNormals.Length == blendShapeVertices.Length && !exportOnlyBlendShapePosition;

            // var blendShapeTangents = mesh.tangents.Select(y => (Vector3)y).ToArray();
            // //var useTangent = usePosition && blendShapeTangents != null && blendShapeTangents.Length == blendShapeVertices.Length;
            // var useTangent = false;

            var frameCount = mesh.GetBlendShapeFrameCount(blendShapeIndex);

            mesh.GetBlendShapeFrameVertices(blendShapeIndex, frameCount - 1, blendShapeVertices, blendShapeNormals, null);

            //
            // invert axis
            //
            for (int i = 0; i < blendShapeVertices.Length; ++i)
            {
                blendShapeVertices[i] = axisInverter.InvertVector3(blendShapeVertices[i]);
            }
            for (int i = 0; i < blendShapeNormals.Length; ++i)
            {
                blendShapeNormals[i] = axisInverter.InvertVector3(blendShapeNormals[i]);
            }

            var positions = mesh.vertices;

            for (int i = 0; i < positions.Length; ++i)
            {
                positions[i] = axisInverter.InvertVector3(positions[i]);
            }

            var normals = mesh.normals;

            for (int i = 0; i < normals.Length; ++i)
            {
                normals[i] = axisInverter.InvertVector3(normals[i]);
            }

            return(BlendShapeExporter.Export(data,
                                             blendShapeVertices,
                                             exportOnlyBlendShapePosition && useNormal ? null : blendShapeNormals,
                                             useSparseAccessorForMorphTarget));
        }