internal NodeTemplate(Schema2.Node srcNode, int parentIdx, int[] childIndices, bool isolateMemory) { _LogicalSourceIndex = srcNode.LogicalIndex; _ParentIndex = parentIdx; _ChildIndices = childIndices; Name = srcNode.Name; _LocalMatrix = srcNode.LocalMatrix; _LocalTransform = srcNode.LocalTransform; _Scale = new AnimatableProperty <Vector3>(_LocalTransform.Scale); _Rotation = new AnimatableProperty <Quaternion>(_LocalTransform.Rotation); _Translation = new AnimatableProperty <Vector3>(_LocalTransform.Translation); var mw = Transforms.SparseWeight8.Create(srcNode.MorphWeights); _Morphing = new AnimatableProperty <Transforms.SparseWeight8>(mw); foreach (var anim in srcNode.LogicalParent.LogicalAnimations) { var index = anim.LogicalIndex; var name = anim.Name; var scaAnim = anim.FindScaleSampler(srcNode)?.CreateCurveSampler(isolateMemory); if (scaAnim != null) { _Scale.AddCurve(index, name, scaAnim); } var rotAnim = anim.FindRotationSampler(srcNode)?.CreateCurveSampler(isolateMemory); if (rotAnim != null) { _Rotation.AddCurve(index, name, rotAnim); } var traAnim = anim.FindTranslationSampler(srcNode)?.CreateCurveSampler(isolateMemory); if (traAnim != null) { _Translation.AddCurve(index, name, traAnim); } var mrpAnim = anim.FindSparseMorphSampler(srcNode)?.CreateCurveSampler(isolateMemory); if (mrpAnim != null) { _Morphing.AddCurve(index, name, mrpAnim); } } _UsePrecomputed = !(_Scale.IsAnimated | _Rotation.IsAnimated | _Translation.IsAnimated); if (_UsePrecomputed) { _Scale = null; _Rotation = null; _Translation = null; } }
internal InstancedDrawableTemplate(Schema2.Node node, Func <Schema2.Node, int> indexFunc) : base(node, indexFunc) { var instancing = node.GetGpuInstancing(); _Instances = new TRANSFORM[instancing.Count]; for (int i = 0; i < _Instances.Length; ++i) { _Instances[i] = instancing.GetLocalTransform(i); } }
internal NodeTemplate(Schema2.Node srcNode, int parentIdx, int[] childIndices, RuntimeOptions options) { _LogicalSourceIndex = srcNode.LogicalIndex; _ParentIndex = parentIdx; _ChildIndices = childIndices; Name = srcNode.Name; Extras = RuntimeOptions.ConvertExtras(srcNode, options); _LocalTransform = srcNode.LocalTransform; if (_LocalTransform.TryDecompose(out TRANSFORM lxform)) { _Scale = new AnimatableProperty <Vector3>(lxform.Scale); _Rotation = new AnimatableProperty <Quaternion>(lxform.Rotation); _Translation = new AnimatableProperty <Vector3>(lxform.Translation); } var mw = Transforms.SparseWeight8.Create(srcNode.MorphWeights); _Morphing = new AnimatableProperty <Transforms.SparseWeight8>(mw); var isolateMemory = options?.IsolateMemory ?? false; foreach (var anim in srcNode.LogicalParent.LogicalAnimations) { var index = anim.LogicalIndex; var curves = srcNode.GetCurveSamplers(anim); _Scale.SetCurve(index, curves.Scale?.CreateCurveSampler(isolateMemory)); _Rotation.SetCurve(index, curves.Rotation?.CreateCurveSampler(isolateMemory)); _Translation.SetCurve(index, curves.Translation?.CreateCurveSampler(isolateMemory)); _Morphing.SetCurve(index, curves.GetMorphingSampler <Transforms.SparseWeight8>()?.CreateCurveSampler(isolateMemory)); } _UseAnimatedTransforms = _Scale.IsAnimated | _Rotation.IsAnimated | _Translation.IsAnimated; if (!_UseAnimatedTransforms) { _Scale = null; _Rotation = null; _Translation = null; } }
internal SkinnedDrawableReference(Schema2.Node node, Func <Schema2.Node, int> indexFunc) : base(node) { var skin = node.Skin; _MorphNodeIndex = indexFunc(node); _JointsNodeIndices = new int[skin.JointsCount]; _BindMatrices = new System.Numerics.Matrix4x4[skin.JointsCount]; for (int i = 0; i < _JointsNodeIndices.Length; ++i) { var jm = skin.GetJoint(i); _JointsNodeIndices[i] = indexFunc(jm.Item1); _BindMatrices[i] = jm.Item2; } }
internal SkinnedDrawableTemplate(Schema2.Node node, Func <Schema2.Node, int> indexFunc) : base(node) { var skin = node.Skin; _MorphNodeIndex = indexFunc(node); _JointsNodeIndices = new int[skin.JointsCount]; _BindMatrices = new Matrix4x4[skin.JointsCount]; for (int i = 0; i < _JointsNodeIndices.Length; ++i) { var(j, ibm) = skin.GetJoint(i); _JointsNodeIndices[i] = indexFunc(j); _BindMatrices[i] = ibm; } }
internal RigidDrawableTemplate(Schema2.Node node, Func <Schema2.Node, int> indexFunc) : base(node) { _NodeIndex = indexFunc(node); }
protected DrawableTemplate(Schema2.Node node) { _LogicalMeshIndex = node.Mesh.LogicalIndex; _NodeName = node.Name; }
internal StaticDrawableReference(Schema2.Node node, Func <Schema2.Node, int> indexFunc) : base(node) { _NodeIndex = indexFunc(node); }
protected DrawableReference(Schema2.Node node) { _LogicalMeshIndex = node.Mesh.LogicalIndex; }