MCPcopy
hub / github.com/g3n/engine / newMeshTriangles

Function newMeshTriangles

loader/collada/geometry.go:310–488  ·  view source on GitHub ↗
(m *Mesh, tr *Triangles)

Source from the content-addressed store, hash-verified

308}
309
310func newMeshTriangles(m *Mesh, tr *Triangles) (*geometry.Geometry, uint32, error) {
311
312 // Get vertices positions
313 if len(m.Vertices.Input) != 1 {
314 return nil, 0, fmt.Errorf("Mesh.Vertices.Input length not supported")
315 }
316 vinp := m.Vertices.Input[0]
317 if vinp.Semantic != "POSITION" {
318 return nil, 0, fmt.Errorf("Mesh.Vertices.Input.Semantic:%s not supported", vinp.Semantic)
319 }
320
321 // Get vertices input source
322 inps := getMeshSource(m, vinp.Source)
323 if inps == nil {
324 return nil, 0, fmt.Errorf("Source:%s not found", vinp.Source)
325 }
326
327 // Get vertices input float array
328 // Ignore Accessor (??)
329 posArray, ok := inps.ArrayElement.(*FloatArray)
330 if !ok {
331 return nil, 0, fmt.Errorf("Mesh.Vertices.Input.Source not FloatArray")
332 }
333
334 // Creates buffers
335 positions := math32.NewArrayF32(0, 0)
336 normals := math32.NewArrayF32(0, 0)
337 uvs := math32.NewArrayF32(0, 0)
338 indices := math32.NewArrayU32(0, 0)
339
340 // Creates vertices attributes map for reusing indices
341 mVindex := make(map[[8]float32]uint32)
342 var index uint32
343 geomGroups := make([]geometry.Group, 0)
344 groupMatindex := 0
345
346 // Get VERTEX input
347 inpVertex := getInputSemantic(tr.Input, "VERTEX")
348 if inpVertex == nil {
349 return nil, 0, fmt.Errorf("VERTEX input not found")
350 }
351
352 // Get optional NORMAL input
353 inpNormal := getInputSemantic(tr.Input, "NORMAL")
354 var normArray *FloatArray
355 if inpNormal != nil {
356 // Get normals source
357 source := getMeshSource(m, inpNormal.Source)
358 if source == nil {
359 return nil, 0, fmt.Errorf("NORMAL source:%s not found", inpNormal.Source)
360 }
361 // Get normals source float array
362 normArray, ok = source.ArrayElement.(*FloatArray)
363 if !ok {
364 return nil, 0, fmt.Errorf("NORMAL source:%s not float array", inpNormal.Source)
365 }
366 }
367

Callers 1

newMeshFunction · 0.85

Calls 14

SizeMethod · 0.95
AppendMethod · 0.95
AppendMethod · 0.95
AddVBOMethod · 0.95
SizeMethod · 0.95
SetIndicesMethod · 0.95
AddGroupListMethod · 0.95
NewArrayF32Function · 0.92
NewArrayU32Function · 0.92
NewGeometryFunction · 0.92
NewVBOFunction · 0.92
getMeshSourceFunction · 0.85

Tested by

no test coverage detected