Creates a geometry from a polylist Only triangles are supported
(m *Mesh, pels []interface{})
| 110 | // Creates a geometry from a polylist |
| 111 | // Only triangles are supported |
| 112 | func newMeshPolylist(m *Mesh, pels []interface{}) (*geometry.Geometry, uint32, error) { |
| 113 | |
| 114 | // Get vertices positions |
| 115 | if len(m.Vertices.Input) != 1 { |
| 116 | return nil, 0, fmt.Errorf("Mesh.Vertices.Input length not supported") |
| 117 | } |
| 118 | vinp := m.Vertices.Input[0] |
| 119 | if vinp.Semantic != "POSITION" { |
| 120 | return nil, 0, fmt.Errorf("Mesh.Vertices.Input.Semantic:%s not supported", vinp.Semantic) |
| 121 | } |
| 122 | |
| 123 | // Get vertices input source |
| 124 | inps := getMeshSource(m, vinp.Source) |
| 125 | if inps == nil { |
| 126 | return nil, 0, fmt.Errorf("Source:%s not found", vinp.Source) |
| 127 | } |
| 128 | |
| 129 | // Get vertices input float array |
| 130 | // Ignore Accessor (??) |
| 131 | posArray, ok := inps.ArrayElement.(*FloatArray) |
| 132 | if !ok { |
| 133 | return nil, 0, fmt.Errorf("Mesh.Vertices.Input.Source not FloatArray") |
| 134 | } |
| 135 | |
| 136 | // Creates buffers |
| 137 | positions := math32.NewArrayF32(0, 0) |
| 138 | normals := math32.NewArrayF32(0, 0) |
| 139 | uvs := math32.NewArrayF32(0, 0) |
| 140 | indices := math32.NewArrayU32(0, 0) |
| 141 | |
| 142 | // Creates vertices attributes map for reusing indices |
| 143 | mVindex := make(map[[8]float32]uint32) |
| 144 | var index uint32 |
| 145 | geomGroups := make([]geometry.Group, 0) |
| 146 | groupMatindex := 0 |
| 147 | // For each Polylist |
| 148 | for _, pel := range pels { |
| 149 | // Checks if element is Polylist |
| 150 | pl, ok := pel.(*Polylist) |
| 151 | if !ok { |
| 152 | return nil, 0, fmt.Errorf("Element is not a Polylist") |
| 153 | } |
| 154 | // If Polylist has not inputs, ignore |
| 155 | if pl.Input == nil || len(pl.Input) == 0 { |
| 156 | continue |
| 157 | } |
| 158 | // Checks if all Vcount elements are triangles |
| 159 | for _, v := range pl.Vcount { |
| 160 | if v != 3 { |
| 161 | return nil, 0, fmt.Errorf("Only triangles are supported in Polylist") |
| 162 | } |
| 163 | } |
| 164 | // Get VERTEX input |
| 165 | inpVertex := getInputSemantic(pl.Input, "VERTEX") |
| 166 | if inpVertex == nil { |
| 167 | return nil, 0, fmt.Errorf("VERTEX input not found") |
| 168 | } |
| 169 |
no test coverage detected