ActiveMorphTargets sorts the morph targets by weight and returns the top n morph targets with largest weight.
()
| 118 | |
| 119 | // ActiveMorphTargets sorts the morph targets by weight and returns the top n morph targets with largest weight. |
| 120 | func (mg *MorphGeometry) ActiveMorphTargets() ([]*Geometry, []float32) { |
| 121 | |
| 122 | numTargets := len(mg.targets) |
| 123 | if numTargets == 0 { |
| 124 | return nil, nil |
| 125 | } |
| 126 | |
| 127 | if numTargets <= MaxActiveMorphTargets { |
| 128 | // No need to sort - just return the targets and weights directly |
| 129 | return mg.targets, mg.weights |
| 130 | } else { |
| 131 | // Need to sort them by weight and only return the top N morph targets with largest weight (N = MaxActiveMorphTargets) |
| 132 | // TODO test this (more than [MaxActiveMorphTargets] morph targets) |
| 133 | sortedMorphTargets := make([]*Geometry, numTargets) |
| 134 | copy(sortedMorphTargets, mg.targets) |
| 135 | sort.Slice(sortedMorphTargets, func(i, j int) bool { |
| 136 | return mg.weights[i] > mg.weights[j] |
| 137 | }) |
| 138 | |
| 139 | sortedWeights := make([]float32, numTargets) |
| 140 | copy(sortedWeights, mg.weights) |
| 141 | sort.Slice(sortedWeights, func(i, j int) bool { |
| 142 | return mg.weights[i] > mg.weights[j] |
| 143 | }) |
| 144 | return sortedMorphTargets, sortedWeights |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // SetIndices sets the indices array for this geometry. |
| 149 | func (mg *MorphGeometry) SetIndices(indices math32.ArrayU32) { |