public static void BuildTargetAttributes(ref Dictionary <string, AttributeAccessor> attributes) { if (attributes.ContainsKey(SemanticProperties.POSITION)) { var attributeAccessor = attributes[SemanticProperties.POSITION]; NumericArray resultArray = attributeAccessor.AccessorContent; byte[] bufferViewCache; uint offset = LoadBufferView(attributeAccessor, out bufferViewCache); attributeAccessor.AccessorId.Value.AsVector3Array(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.NORMAL)) { var attributeAccessor = attributes[SemanticProperties.NORMAL]; NumericArray resultArray = attributeAccessor.AccessorContent; byte[] bufferViewCache; uint offset = LoadBufferView(attributeAccessor, out bufferViewCache); attributeAccessor.AccessorId.Value.AsVector3Array(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.TANGENT)) { var attributeAccessor = attributes[SemanticProperties.TANGENT]; NumericArray resultArray = attributeAccessor.AccessorContent; byte[] bufferViewCache; uint offset = LoadBufferView(attributeAccessor, out bufferViewCache); attributeAccessor.AccessorId.Value.AsVector3Array(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } }
/// <summary> /// Uses the accessor to parse the buffer into arrays needed to construct the animation /// </summary> /// <param name="samplers">A dictionary mapping AttributeAccessor lists to their target types public static void BuildAnimationSamplers(ref Dictionary <string, List <AttributeAccessor> > samplers) { foreach (var samplerSet in samplers) { foreach (var attributeAccessor in samplerSet.Value) { NumericArray resultArray = attributeAccessor.AccessorContent; uint offset = LoadBufferView(attributeAccessor, out byte[] bufferViewCache); switch (samplerSet.Key) { case "time": attributeAccessor.AccessorId.Value.AsFloatArray(ref resultArray, bufferViewCache, offset); break; case "translation": case "scale": attributeAccessor.AccessorId.Value.AsVector3Array(ref resultArray, bufferViewCache, offset); break; case "rotation": attributeAccessor.AccessorId.Value.AsVector4Array(ref resultArray, bufferViewCache, offset); break; } attributeAccessor.AccessorContent = resultArray; } } }
public static void BuildBindPoseSamplers(ref AttributeAccessor attributeAccessor) { NumericArray resultArray = attributeAccessor.AccessorContent; uint offset = LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsMatrix4x4Array(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; }
/// <summary> /// Uses the accessor to parse the buffer into attributes needed to construct the mesh primitive /// </summary> /// <param name="attributes">A list of attributes to parse</param> public static void BuildMeshAttributes(ref Dictionary <string, AttributeAccessor> attributes) { foreach (var kvp in attributes) { var attributeAccessor = kvp.Value; NumericArray resultArray = attributeAccessor.AccessorContent; uint offset = LoadBufferView(attributeAccessor, out byte[] bufferViewCache); switch (kvp.Key) { case SemanticProperties.POSITION: attributeAccessor.AccessorId.Value.AsVertexArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.NORMAL: attributeAccessor.AccessorId.Value.AsNormalArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.TANGENT: attributeAccessor.AccessorId.Value.AsTangentArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.TEXCOORD_0: case SemanticProperties.TEXCOORD_1: case SemanticProperties.TEXCOORD_2: case SemanticProperties.TEXCOORD_3: attributeAccessor.AccessorId.Value.AsTexcoordArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.COLOR_0: attributeAccessor.AccessorId.Value.AsColorArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.WEIGHTS_0: case SemanticProperties.JOINTS_0: case SemanticProperties.JOINTS_1: attributeAccessor.AccessorId.Value.AsVector4Array(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.INDICES: attributeAccessor.AccessorId.Value.AsIntArray(ref resultArray, bufferViewCache, offset); break; default: UnityEngine.Debug.LogWarning($"Unrecognized mesh attribute [{kvp.Key}]"); break; } attributeAccessor.AccessorContent = resultArray; } }
public static void BuildTargetAttributes(ref Dictionary <string, AttributeAccessor> attributes) { foreach (var kvp in attributes) { var attributeAccessor = kvp.Value; NumericArray resultArray = attributeAccessor.AccessorContent; byte[] bufferViewCache; uint offset = LoadBufferView(attributeAccessor, out bufferViewCache); switch (kvp.Key) { case SemanticProperties.POSITION: case SemanticProperties.NORMAL: case SemanticProperties.TANGENT: attributeAccessor.AccessorId.Value.AsVector3Array(ref resultArray, bufferViewCache, offset); break; default: throw new System.Exception($"Unrecognized morph target attribute {kvp.Key}"); } attributeAccessor.AccessorContent = resultArray; } }
/// <summary> /// Uses the accessor to parse the buffer into attributes needed to construct the mesh primitive /// </summary> /// <param name="attributes">A dictionary that contains a mapping of attribute name to data needed to parse</param> public static void BuildMeshAttributes(ref Dictionary <string, AttributeAccessor> attributes) { if (attributes.ContainsKey(SemanticProperties.POSITION)) { var attributeAccessor = attributes[SemanticProperties.POSITION]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsVertexArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.INDICES)) { var attributeAccessor = attributes[SemanticProperties.INDICES]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsTriangles(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.NORMAL)) { var attributeAccessor = attributes[SemanticProperties.NORMAL]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsNormalArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.TexCoord(0))) { var attributeAccessor = attributes[SemanticProperties.TexCoord(0)]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsTexcoordArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.TexCoord(1))) { var attributeAccessor = attributes[SemanticProperties.TexCoord(1)]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsTexcoordArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.TexCoord(2))) { var attributeAccessor = attributes[SemanticProperties.TexCoord(2)]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsTexcoordArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.TexCoord(3))) { var attributeAccessor = attributes[SemanticProperties.TexCoord(3)]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsTexcoordArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.Color(0))) { var attributeAccessor = attributes[SemanticProperties.Color(0)]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsColorArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } if (attributes.ContainsKey(SemanticProperties.TANGENT)) { var attributeAccessor = attributes[SemanticProperties.TANGENT]; NumericArray resultArray = attributeAccessor.AccessorContent; int offset = (int)LoadBufferView(attributeAccessor, out byte[] bufferViewCache); attributeAccessor.AccessorId.Value.AsTangentArray(ref resultArray, bufferViewCache, offset); attributeAccessor.AccessorContent = resultArray; } }
/// <summary> /// Uses the accessor to parse the buffer into attributes needed to construct the mesh primitive /// </summary> /// <param name="attributes">A list of attributes to parse</param> public static void BuildMeshAttributes(ref Dictionary <string, AttributeAccessor> attributes) { List <string> unrecognizedAttributes = new List <string>(); foreach (var kvp in attributes) { var attributeAccessor = kvp.Value; NumericArray resultArray = attributeAccessor.AccessorContent; uint offset = LoadBufferView(attributeAccessor, out byte[] bufferViewCache); switch (kvp.Key) { case SemanticProperties.POSITION: attributeAccessor.AccessorId.Value.AsVertexArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.NORMAL: attributeAccessor.AccessorId.Value.AsNormalArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.TANGENT: attributeAccessor.AccessorId.Value.AsTangentArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.TEXCOORD_0: case SemanticProperties.TEXCOORD_1: case SemanticProperties.TEXCOORD_2: case SemanticProperties.TEXCOORD_3: attributeAccessor.AccessorId.Value.AsTexcoordArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.COLOR_0: attributeAccessor.AccessorId.Value.AsColorArray(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.WEIGHTS_0: case SemanticProperties.JOINTS_0: attributeAccessor.AccessorId.Value.AsVector4Array(ref resultArray, bufferViewCache, offset); break; case SemanticProperties.INDICES: attributeAccessor.AccessorId.Value.AsUIntArray(ref resultArray, bufferViewCache, offset); break; default: unrecognizedAttributes.Add(kvp.Key); continue; } attributeAccessor.AccessorContent = resultArray; } foreach (var attrib in unrecognizedAttributes) { attributes.Remove(attrib); } // TODO This should be a warning. Unrecognized attributes (e.g. TEXCOORD_4) should not cause full exceptions. if (unrecognizedAttributes.Count > 0) { throw new GLTFLoadException($"Unrecognized mesh attributes [{string.Join(", ", unrecognizedAttributes.ToArray())}]"); } }
public AttributeAccessor() { AccessorContent = new NumericArray(); }
public static float[] ParseMorphWeights(Accessor accessor, byte[] bufferData) { NumericArray array = new NumericArray(); return(accessor.AsFloatArray(ref array, bufferData)); }
public static float[] ParseKeyframeTimes(Accessor accessor, byte[] bufferData) { NumericArray array = new NumericArray(); return(accessor.AsFloatArray(ref array, bufferData)); }
public static Math.Vector3[] ParseVector3Keyframes(Accessor accessor, byte[] bufferData) { NumericArray array = new NumericArray(); return(accessor.AsVector3Array(ref array, bufferData, false)); }
public static Math.Vector4[] ParseRotationKeyframes(Accessor accessor, byte[] bufferData) { NumericArray array = new NumericArray(); return(accessor.AsVector4Array(ref array, bufferData, true)); }