qmuntal / gltf

Go library for encoding glTF 2.0 files
https://www.khronos.org/gltf/
BSD 2-Clause "Simplified" License
241 stars 32 forks source link

Accept `*gltf.Primitive` instead of `*gltf.Accessor` in `gltf/modeler` functions? #71

Closed myaaaaaaaaa closed 1 year ago

myaaaaaaaaa commented 1 year ago

At a cursory glance, this would remove some redundancies in specifying Index/Position/Color/etc multiple times.

modeler.Read*()

 primitive := doc.Meshes[0].Primitives[0]
-position, err := modeler.ReadPosition(doc, doc.Accessors[primitive.Attributes[gltf.POSITION]], nil)
+position, err := modeler.ReadPosition(doc, primitive, nil)

-color, err := modeler.ReadColor(doc, doc.Accessors[primitive.Attributes[gltf.COLOR_0]], nil)
+color, err := modeler.ReadColor(doc, primitive, 0, nil)

modeler.Write*()

 primitive := &gltf.Primitive{}
 doc.Meshes = []*gltf.Mesh{{
     Name: "Pyramid",
     Primitives: []*gltf.Primitive{primitive},
 }}

-primitive.Indices = gltf.Index(modeler.WriteIndices(doc, indices))
+modeler.WriteIndices(doc, primitive, indices)

-primitive.Attributes[gltf.POSITION] = modeler.WritePosition(doc, position)
+modeler.WritePosition(doc, primitive, position)

-primitive.Attributes[gltf.COLOR_0] = modeler.WriteColor(doc, color)
+modeler.WriteColor(doc, primitive, 0, color)
myaaaaaaaaa commented 1 year ago

Closing in favor of #72 , sorry for the noise