void _AnimateNodes(int ss) { if (_shape.Nodes.Length == 0) return; // temporary storage for node transforms int numNodes = _shape.Nodes.Length; if (_nodeCurrentRotations == null || _nodeCurrentRotations.Length < numNodes) { // grow all these arrays together...no need to check each individually TorqueUtil.GrowArray<Quaternion>(ref _nodeCurrentRotations, numNodes); TorqueUtil.GrowArray<Vector3>(ref _nodeCurrentTranslations, numNodes); TorqueUtil.GrowArray<Thread>(ref _workRotationThreads, numNodes); TorqueUtil.GrowArray<Thread>(ref _workTranslationThreads, numNodes); } BitVector rotBeenSet = new BitVector(); BitVector tranBeenSet = new BitVector(); BitVector scaleBeenSet = new BitVector(); rotBeenSet.SetSize(numNodes); rotBeenSet.SetAll(); tranBeenSet.SetSize(numNodes); tranBeenSet.SetAll(); scaleBeenSet.SetSize(numNodes); scaleBeenSet.SetAll(); int firstBlend = _threadList.Count; for (int i = 0; i < _threadList.Count; i++) { Thread th = _threadList[i]; if (th.Sequence.IsBlend()) { // blend sequences need default (if not Set by other _sequence) // break rather than continue because the rest will be blends too firstBlend = i; break; } rotBeenSet.TakeAway(th.Sequence.DoesRotationMatter); tranBeenSet.TakeAway(th.Sequence.DoesTranslationMatter); scaleBeenSet.TakeAway(th.Sequence.DoesScaleMatter); } rotBeenSet.TakeAway(_handsOffNodes); tranBeenSet.TakeAway(_handsOffNodes); // all the nodes marked above need to have the default transform int a = _shape.SubShapeFirstNode[ss]; int b = a + _shape.SubShapeNodeCount[ss]; for (int i = a; i < b; i++) { if (rotBeenSet.Test(i)) { _shape.DefaultRotations[i].Get(out _nodeCurrentRotations[i]); _workRotationThreads[i] = null; } if (tranBeenSet.Test(i)) { _nodeCurrentTranslations[i] = _shape.DefaultTranslations[i]; _workTranslationThreads[i] = null; } } // don't want a transform in these cases... rotBeenSet.Overlap(_handsOffNodes); tranBeenSet.Overlap(_handsOffNodes); // default Scale if (ScaleCurrentlyAnimated()) _HandleDefaultScale(a, b, ref scaleBeenSet); // handle non-blend sequences for (int i = 0; i < firstBlend; i++) { Thread th = _threadList[i]; int nodeIndex = th.Sequence.DoesRotationMatter.Start(); int end = b; for (int j = 0; nodeIndex < end; th.Sequence.DoesRotationMatter.Next(ref nodeIndex), j++) { // skip nodes outside of this detail if (nodeIndex < a) continue; if (!rotBeenSet.Test(nodeIndex)) { Quaternion q1, q2; _shape.GetRotation(th.Sequence, th._keyNum1, j, out q1); _shape.GetRotation(th.Sequence, th._keyNum2, j, out q2); Transform.Interpolate(q1, q2, th._keyPos, out _nodeCurrentRotations[nodeIndex]); rotBeenSet.Set(nodeIndex); _workRotationThreads[nodeIndex] = th; } } nodeIndex = th.Sequence.DoesTranslationMatter.Start(); end = b; for (int j = 0; nodeIndex < end; th.Sequence.DoesTranslationMatter.Next(ref nodeIndex), j++) { if (nodeIndex < a) continue; if (!tranBeenSet.Test(nodeIndex)) { Vector3 p1 = _shape.GetTranslation(th.Sequence, th._keyNum1, j); Vector3 p2 = _shape.GetTranslation(th.Sequence, th._keyNum2, j); Transform.Interpolate(p1, p2, th._keyPos, out _nodeCurrentTranslations[nodeIndex]); _workTranslationThreads[nodeIndex] = th; tranBeenSet.Set(nodeIndex); } } if (ScaleCurrentlyAnimated()) _HandleAnimatedScale(th, a, b, ref scaleBeenSet); } // transitions... if (InTransition()) _HandleTransitionNodes(a, b); // compute transforms for (int i = a; i < b; i++) if (!_handsOffNodes.Test(i)) Transform.SetMatrix(_nodeCurrentRotations[i], _nodeCurrentTranslations[i], out _nodeTransforms[i]); // add Scale onto transforms if (ScaleCurrentlyAnimated()) _HandleNodeScale(a, b); // get callback transforms... if (_callbackNodes != null) for (int i = 0; i < _callbackNodes.Count; i++) _callbackNodes[i].Transform.GetLocalMatrix(out _nodeTransforms[_callbackNodes[i].NodeIndex], true); // handle blend sequences for (int i = firstBlend; i < _threadList.Count; i++) { Thread th = _threadList[i]; if (th._blendDisabled) continue; _HandleBlendSequence(th, a, b); } // multiply transforms... for (int i = a; i < b; i++) { int parentIdx = _shape.Nodes[i].ParentIndex; if (parentIdx >= 0) _nodeTransforms[i] = Matrix.Multiply(_nodeTransforms[i], _nodeTransforms[parentIdx]); } }
void _AnimateVisibility(int ss) { if (_meshObjects.Length == 0) return; // find out who needs default values Set BitVector beenSet = new BitVector(); beenSet.SetSize(_meshObjects.Length); beenSet.SetAll(); for (int i = 0; i < _threadList.Count; i++) beenSet.TakeAway(_threadList[i].Sequence.DoesVisibilityMatter); // Set defaults int a = _shape.SubShapeFirstObject[ss]; int b = a + _shape.SubShapeObjectCount[ss]; for (int i = a; i < b; i++) { if (beenSet.Test(i)) _meshObjects[i].Visibility = _shape.ObjectStates[i].Visibility; } // go through each thread and Set visibility on those objects that // are not Set yet and are controlled by that thread BitVector objectMatters = new BitVector(); for (int i = 0; i < _threadList.Count; i++) { Thread th = _threadList[i]; objectMatters.Copy(ref th.Sequence.DoesFrameMatter); objectMatters.Overlap(th.Sequence.DoesMaterialFrameMatter); objectMatters.Overlap(th.Sequence.DoesVisibilityMatter); // skip to beginining of this sub-shape int j = 0; int start = objectMatters.Start(); int end = b; for (int objectIndex = start; objectIndex < b; objectMatters.Next(ref objectIndex), j++) { if (!beenSet.Test(objectIndex) && th.Sequence.DoesVisibilityMatter.Test(objectIndex)) { float state1 = _shape.GetObjectState(th.Sequence, th._keyNum1, j).Visibility; float state2 = _shape.GetObjectState(th.Sequence, th._keyNum2, j).Visibility; if ((state1 - state2) * (state1 - state2) > 0.99f) // goes from 0 to 1 -- discreet jump _meshObjects[objectIndex].Visibility = th._keyPos < 0.5f ? state1 : state2; else // Interpolate between keyframes when visibility change is gradual _meshObjects[objectIndex].Visibility = (1.0f - th._keyPos) * state1 + th._keyPos * state2; // record change so that later threads don't over-write us... beenSet.Set(objectIndex); } } } }
void _AnimateMatFrame(int ss) { if (_meshObjects.Length == 0) return; // find out who needs default values Set BitVector beenSet = new BitVector(); beenSet.SetSize(_meshObjects.Length); beenSet.SetAll(); for (int i = 0; i < _threadList.Count; i++) beenSet.TakeAway(_threadList[i].Sequence.DoesMaterialFrameMatter); // Set defaults int a = _shape.SubShapeFirstObject[ss]; int b = a + _shape.SubShapeObjectCount[ss]; for (int i = a; i < b; i++) { if (beenSet.Test(i)) _meshObjects[i].MaterialFrame = _shape.ObjectStates[i].MaterialFrameIndex; } // go through each thread and Set matFrame on those objects that // are not Set yet and are controlled by that thread BitVector objectMatters = new BitVector(); for (int i = 0; i < _threadList.Count; i++) { Thread th = _threadList[i]; objectMatters.Copy(ref th.Sequence.DoesFrameMatter); objectMatters.Overlap(th.Sequence.DoesMaterialFrameMatter); objectMatters.Overlap(th.Sequence.DoesVisibilityMatter); // skip to beginining of this sub-shape int j = 0; int start = objectMatters.Start(); int end = b; for (int objectIndex = start; objectIndex < end; objectMatters.Next(ref objectIndex), j++) { if (!beenSet.Test(objectIndex) && th.Sequence.DoesMaterialFrameMatter.Test(objectIndex)) { int key = (th._keyPos < 0.5f) ? th._keyNum1 : th._keyNum2; _meshObjects[objectIndex].MaterialFrame = _shape.GetObjectState(th.Sequence, key, j).MaterialFrameIndex; // record change so that later threads don't over-write us... beenSet.Set(objectIndex); } } } }