AddMorphTargets add multiple morph targets to the morph geometry. Morph target deltas are calculated internally and the morph target geometries are altered to hold the deltas instead.
(morphTargets ...*Geometry)
| 62 | // AddMorphTargets add multiple morph targets to the morph geometry. |
| 63 | // Morph target deltas are calculated internally and the morph target geometries are altered to hold the deltas instead. |
| 64 | func (mg *MorphGeometry) AddMorphTargets(morphTargets ...*Geometry) { |
| 65 | |
| 66 | for i := range morphTargets { |
| 67 | mg.weights = append(mg.weights, 0) |
| 68 | // Calculate deltas for VertexPosition |
| 69 | vertexIdx := 0 |
| 70 | baseVertices := mg.baseGeometry.VBO(gls.VertexPosition).Buffer() |
| 71 | morphTargets[i].OperateOnVertices(func(vertex *math32.Vector3) bool { |
| 72 | var baseVertex math32.Vector3 |
| 73 | baseVertices.GetVector3(vertexIdx*3, &baseVertex) |
| 74 | vertex.Sub(&baseVertex) |
| 75 | vertexIdx++ |
| 76 | return false |
| 77 | }) |
| 78 | // Calculate deltas for VertexNormal if attribute is present in target geometry |
| 79 | // It is assumed that if VertexNormals are present in a target geometry then they are also present in the base geometry |
| 80 | normalIdx := 0 |
| 81 | baseNormalsVBO := mg.baseGeometry.VBO(gls.VertexNormal) |
| 82 | if baseNormalsVBO != nil { |
| 83 | baseNormals := baseNormalsVBO.Buffer() |
| 84 | morphTargets[i].OperateOnVertexNormals(func(normal *math32.Vector3) bool { |
| 85 | var baseNormal math32.Vector3 |
| 86 | baseNormals.GetVector3(normalIdx*3, &baseNormal) |
| 87 | normal.Sub(&baseNormal) |
| 88 | normalIdx++ |
| 89 | return false |
| 90 | }) |
| 91 | } |
| 92 | // TODO Calculate deltas for VertexTangents |
| 93 | } |
| 94 | mg.targets = append(mg.targets, morphTargets...) |
| 95 | |
| 96 | // Update all target attributes if we have few enough that we are able to send them |
| 97 | // all to the shader without sorting and choosing the ones with highest current weight |
| 98 | if len(mg.targets) <= MaxActiveMorphTargets { |
| 99 | mg.UpdateTargetAttributes(mg.targets) |
| 100 | } |
| 101 | |
| 102 | } |
| 103 | |
| 104 | // AddMorphTargetDeltas add multiple morph target deltas to the morph geometry. |
| 105 | func (mg *MorphGeometry) AddMorphTargetDeltas(morphTargetDeltas ...*Geometry) { |
nothing calls this directly
no test coverage detected