MCPcopy Index your code
hub / github.com/g3n/engine / NewAnimationTargets

Method NewAnimationTargets

loader/collada/animation.go:104–198  ·  view source on GitHub ↗

NewAnimationTargets creates and returns a map of all animation targets contained in the decoded Collada document and for the previously decoded scene. The map is indexed by the node loaderID.

(scene core.INode)

Source from the content-addressed store, hash-verified

102// contained in the decoded Collada document and for the previously decoded scene.
103// The map is indexed by the node loaderID.
104func (d *Decoder) NewAnimationTargets(scene core.INode) (map[string]*AnimationTarget, error) {
105
106 if d.dom.LibraryAnimations == nil {
107 return nil, fmt.Errorf("No animations found")
108 }
109
110 // Maps target node to its animation target instance
111 targetsMap := make(map[string]*AnimationTarget)
112
113 // For each Collada animation element
114 for _, ca := range d.dom.LibraryAnimations.Animation {
115
116 // For each Collada channel for this animation
117 for _, cc := range ca.Channel {
118
119 // Separates the channel target in target id and target action
120 parts := strings.Split(cc.Target, "/")
121 if len(parts) < 2 {
122 return nil, fmt.Errorf("Channel target invalid")
123 }
124 targetID := parts[0]
125 targetAction := parts[1]
126
127 // Get the target node object referenced by the target id from the specified scene.
128 target := scene.GetNode().FindLoaderID(targetID)
129 if target == nil {
130 return nil, fmt.Errorf("Target node id:%s not found", targetID)
131 }
132
133 // Get reference to the AnimationTarget for this target in the local map
134 // If not found creates the animation target and inserts in the map
135 at := targetsMap[targetID]
136 if at == nil {
137 at = new(AnimationTarget)
138 at.target = target
139 at.matrix = target.GetNode().Matrix()
140 targetsMap[targetID] = at
141 }
142
143 // Creates the sampler instance specified from the channel source
144 si, err := NewSamplerInstance(ca, cc.Source)
145 if err != nil {
146 return nil, err
147 }
148
149 // Sets the action function from the target action
150 var af ActionFunc
151 switch targetAction {
152 case "location.X":
153 af = actionPositionX
154 case "location.Y":
155 af = actionPositionY
156 case "location.Z":
157 af = actionPositionZ
158 case "rotationX.ANGLE":
159 af = actionRotationX
160 case "rotationY.ANGLE":
161 af = actionRotationY

Callers

nothing calls this directly

Calls 5

NewSamplerInstanceFunction · 0.85
SplitMethod · 0.80
FindLoaderIDMethod · 0.80
MatrixMethod · 0.80
GetNodeMethod · 0.65

Tested by

no test coverage detected