Exemplo n.º 1
0
 public static CurveSampler FromGltf(GltfSerialization.GltfStorage storage, int inIndex, int outIndex)
 {
     return(new CurveSampler
     {
         In = storage.AccessorFromGltf(inIndex),
         Out = storage.AccessorFromGltf(outIndex),
     });
 }
Exemplo n.º 2
0
        static void CreateBufferAccessorAndAdd(GltfSerialization.GltfStorage storage, int accessorIndex,
                                               VertexBuffer b, string key)
        {
            var a = storage.AccessorFromGltf(accessorIndex);

            if (a != null)
            {
                b.Add(key, a);
            }
        }
Exemplo n.º 3
0
        public static VertexBuffer FromGltf(this GltfAttributes attributes, GltfSerialization.GltfStorage storage)
        {
            var b = new VertexBuffer();

            b.Add(VertexBuffer.PositionKey, storage.AccessorFromGltf(attributes.POSITION));
            CreateBufferAccessorAndAdd(storage, attributes.NORMAL, b, VertexBuffer.NormalKey);
            CreateBufferAccessorAndAdd(storage, attributes.TEXCOORD_0, b, VertexBuffer.TexCoordKey);
            CreateBufferAccessorAndAdd(storage, attributes.TANGENT, b, VertexBuffer.TangentKey);
            CreateBufferAccessorAndAdd(storage, attributes.COLOR_0, b, VertexBuffer.ColorKey);
            CreateBufferAccessorAndAdd(storage, attributes.JOINTS_0, b, VertexBuffer.JointKey);
            CreateBufferAccessorAndAdd(storage, attributes.WEIGHTS_0, b, VertexBuffer.WeightKey);
            return(b);
        }
Exemplo n.º 4
0
        static Mesh FromGltf(GltfSerialization.GltfStorage storage, GltfMesh x, GltfPrimitive primitive, bool isShared)
        {
            var mesh = new Mesh((TopologyType)primitive.mode)
            {
                VertexBuffer = primitive.attributes.FromGltf(storage)
            };

            if (isShared)
            {
                // create joined index buffer
                mesh.IndexBuffer = storage.IndexBufferFromGltf(x.primitives.Select(y => y.indices).ToArray());
            }
            else
            {
                mesh.IndexBuffer = storage.AccessorFromGltf(primitive.indices);
            }

            if (primitive.targets != null)
            {
                for (int i = 0; i < primitive.targets.Count; ++i)
                {
                    var    gltfTarget = primitive.targets[i];
                    string targetName = null;
                    if (primitive.extras != null &&
                        primitive.extras.targetNames != null &&
                        i < primitive.extras.targetNames.Count
                        )
                    {
                        targetName = primitive.extras.targetNames[i];
                    }
                    var target = new MorphTarget(targetName)
                    {
                        VertexBuffer = gltfTarget.FromGltf(storage)
                    };

                    // validate count
                    foreach (var kv in target.VertexBuffer)
                    {
                        if (kv.Value.Count != mesh.VertexBuffer.Count)
                        {
                            throw new Exception();
                        }
                    }

                    mesh.MorphTargets.Add(target);
                }
            }

            return(mesh);
        }