in packages/gltf-gen/src/meshprimitive.ts [92:133]
public serialize(document: GLTF.GlTf, data: Buffer): GLTF.MeshPrimitive {
if (this.cachedSerialVal !== undefined) {
return this.cachedSerialVal;
}
// just dupe the attribute accessors from the instance parent if one exists
if (this.instanceParent) {
const prim0 = { ...this.instanceParent.serialize(document, data) };
prim0.material = this.material.serialize(document, data);
return this.cachedSerialVal = prim0;
}
const prim: GLTF.MeshPrimitive = {
attributes: {
POSITION: this._serializeAttribute(Vertex.positionAttribute, document, data)
},
indices: this._serializeIndices(document, data)
};
if (this.usesNormals) {
prim.attributes.NORMAL = this._serializeAttribute(Vertex.normalAttribute, document, data);
}
if (this.usesTangents) {
prim.attributes.TANGENT = this._serializeAttribute(Vertex.tangentAttribute, document, data);
}
if (this.usesTexCoord0) {
prim.attributes.TEXCOORD_0 = this._serializeAttribute(Vertex.texCoordAttribute[0], document, data);
}
if (this.usesTexCoord1) {
prim.attributes.TEXCOORD_1 = this._serializeAttribute(Vertex.texCoordAttribute[1], document, data);
}
if (this.usesColor0) {
prim.attributes.COLOR_0 = this._serializeAttribute(Vertex.colorAttribute, document, data);
}
if (this.material) {
prim.material = this.material.serialize(document, data);
}
return this.cachedSerialVal = prim;
}