Esempio n. 1
0
        public Transform getBoneTransform(Node bone)
        {
            SkinnedMesh.requireBoneNotNull(bone);
            Dictionary <Node, Transform> restTransformByBone = this.m_atRestTransformByBone;

            return(this.m_atRestTransformByBone[bone]);
        }
Esempio n. 2
0
        protected override void duplicateTo(ref Object3D ret)
        {
            base.duplicateTo(ref ret);
            SkinnedMesh that      = (SkinnedMesh)ret;
            Group       skeleton1 = this.getSkeleton();
            Group       skeleton2 = (Group)skeleton1.duplicate();

            that.setSkeleton(skeleton2);
            this.duplicateToAddWeight(that, (Node)skeleton1, (Node)skeleton2);
        }
Esempio n. 3
0
 private void addTransformWithoutWeightCheck(
     Node bone,
     int weight,
     int firstVertex,
     int numVertices)
 {
     this.requireIsLegacy();
     SkinnedMesh.requireValidVertexRange(firstVertex, numVertices, (int)ushort.MaxValue);
     this.addBone(bone);
     this.addWeight(bone, weight, firstVertex, numVertices);
 }
Esempio n. 4
0
 public void setSkeleton(Group skeleton)
 {
     SkinnedMesh.requireBoneNotNull((Node)skeleton);
     this.requireVertexBufferNotNull();
     this.m_skeleton = skeleton;
     this.m_skeleton.setParent((Node)this);
     if (!this.isLegacy())
     {
         return;
     }
     this.addTransformWithoutWeightCheck((Node)this.m_skeleton, 0, 0, this.getVertexBuffer().getVertexCount());
 }
Esempio n. 5
0
        public void renderForceAppearanceLoad(Node node, Transform transform)
        {
            this.m_renderNodeList.Clear();
            this.m_transformListPosition = 0;
            this.compileRenderableNodeList(ref node, ref transform, this.m_cameraScope, 0);
            this.m_renderNodeList.Sort();
            int  cameraScope = this.m_cameraScope;
            int  count       = this.m_renderNodeList.Count;
            long num         = 0;

            for (int index = 0; index < count; ++index)
            {
                RenderNode renderNode1 = this.m_renderNodeList[index];
                Mesh       renderNode2 = (Mesh)renderNode1.renderNode;
                if (renderNode2 != null && (renderNode2.getScope() & cameraScope) != 0)
                {
                    AppearanceBase appearance = renderNode1.m_appearance;
                    if (appearance != null)
                    {
                        VertexBuffer vertexBuffer = renderNode1.m_vertexBuffer;
                        IndexBuffer  indexBuffer  = renderNode1.m_indexBuffer;
                        float        alphaFactor  = renderNode2.getAlphaFactor();
                        this.m_renderer.pushModelTransform(renderNode1.compositeTransform);
                        this.m_renderer.processApperance((Appearance)appearance);
                        if ((object)renderNode2.GetType() == (object)typeof(SkinnedMesh) || renderNode2.GetType().IsSubclassOf(typeof(SkinnedMesh)))
                        {
                            SkinnedMesh skinnedMesh = (SkinnedMesh)renderNode2;
                            this.m_renderer.render(vertexBuffer, skinnedMesh.getSkinIndices(), skinnedMesh.getSkinWeights(), skinnedMesh.getBoneTransforms(), indexBuffer, appearance, alphaFactor);
                            num += (long)indexBuffer.getPrimitiveCount();
                        }
                        else
                        {
                            this.m_renderer.render(vertexBuffer, indexBuffer, appearance, alphaFactor);
                            num += (long)indexBuffer.getPrimitiveCount();
                        }
                        this.m_renderer.popModelTransform();
                    }
                }
            }
            if (this.m_renderNodeList.Count > this.m_reservedCapacity)
            {
                this.m_reservedCapacity        = this.m_renderNodeList.Count;
                this.m_renderNodeList.Capacity = this.m_reservedCapacity;
            }
            this.m_renderNodeList.Clear();
            this.m_renderer.restoreToClamp();
        }
Esempio n. 6
0
        private static object loadSkinnedMesh(
            ref DataInputStream @in,
            ref List <Object3D> objectList,
            ref List <Object3D> rootObjectList)
        {
            SkinnedMesh skinnedMesh = new SkinnedMesh();

            Loader.loadMesh((Mesh)skinnedMesh, ref @in, ref objectList, ref rootObjectList);
            Group reference1 = (Group)Loader.getReference(ref @in, ref objectList, ref rootObjectList);

            skinnedMesh.setSkeleton(reference1);
            bool flag = true;

            if (flag)
            {
                skinnedMesh.setLegacy(true);
            }
            int length = Loader.readIntLE(ref @in);

            if (flag)
            {
                for (int index = 0; index < length; ++index)
                {
                    Node reference2  = (Node)Loader.getReference(ref @in, ref objectList, ref rootObjectList);
                    int  firstVertex = Loader.readIntLE(ref @in);
                    int  numVertices = Loader.readIntLE(ref @in);
                    int  weight      = Loader.readIntLE(ref @in);
                    skinnedMesh.addTransform(reference2, weight, firstVertex, numVertices);
                }
            }
            else
            {
                Node[] bones = new Node[length];
                for (int index = 0; index < length; ++index)
                {
                    bones[index] = (Node)Loader.getReference(ref @in, ref objectList, ref rootObjectList);
                }
                skinnedMesh.setBones(bones);
            }
            return((object)skinnedMesh);
        }
Esempio n. 7
0
        protected void addBone(Node bone)
        {
            SkinnedMesh.requireBoneNotNull(bone);
            this.getSkeleton();
            if (this.m_atRestTransformByBone == null)
            {
                this.m_atRestTransformByBone = new Dictionary <Node, Transform>();
            }
            if (this.m_bones == null)
            {
                this.m_bones = new List <Node>();
            }
            if (this.m_atRestTransformByBone.ContainsKey(bone))
            {
                return;
            }
            Transform transform = new Transform();

            this.getTransformTo(bone, ref transform);
            this.m_atRestTransformByBone.Add(bone, transform);
            this.m_bones.Add(bone);
        }
Esempio n. 8
0
        public int getBoneVertices(Node bone, ref int[] indices, ref float[] weights)
        {
            this.requireIsLegacy();
            SkinnedMesh.requireBoneNotNull(bone);
            this.requireVertexBufferNotNull();
            if (!this.m_weightsByBone.ContainsKey(bone))
            {
                return(0);
            }
            int[] numArray1 = this.m_weightsByBone[bone];
            if (numArray1 == null)
            {
                return(0);
            }
            bool flag        = indices.Length == 0;
            int  vertexCount = this.getVertexBuffer().getVertexCount();

            int[] numArray2     = numArray1;
            int[] summedWeights = this.m_summedWeights;
            int   index1        = 0;

            for (int index2 = 0; index2 < vertexCount; ++index2)
            {
                int num1 = numArray2[index2];
                if (num1 != 0)
                {
                    if (!flag)
                    {
                        indices[index1] = index2;
                        int num2 = summedWeights[index2];
                        weights[index1] = (float)num1 / (float)num2;
                    }
                    ++index1;
                }
            }
            return(index1);
        }
Esempio n. 9
0
        protected void addWeight(Node bone, int weight, int firstVertex, int numVertices)
        {
            SkinnedMesh.requireBoneNotNull(bone);
            this.requireVertexBufferNotNull();
            int vertexCount = this.getVertexBuffer().getVertexCount();

            SkinnedMesh.requireValidVertexRange(firstVertex, numVertices, vertexCount);
            if (this.m_weightsByBone == null)
            {
                this.m_weightsByBone = new Dictionary <Node, int[]>();
            }
            int[] numArray1 = this.m_weightsByBone.ContainsKey(bone) ? this.m_weightsByBone[bone] : new int[vertexCount];
            if (this.m_summedWeights.Length == 0)
            {
                this.m_summedWeights = new int[vertexCount];
            }
            int[] numArray2 = numArray1;
            int   num1      = firstVertex + numVertices;

            for (int index = firstVertex; index < num1; ++index)
            {
                int num2 = numArray2[index];
                this.m_summedWeights[index] -= Math.Abs(num2);
                int num3 = num2 + weight;
                this.m_summedWeights[index] += Math.Abs(num3);
                numArray2[index]             = num3;
            }
            if (this.m_weightsByBone.ContainsKey(bone))
            {
                this.m_weightsByBone[bone] = numArray1;
            }
            else
            {
                this.m_weightsByBone.Add(bone, numArray1);
            }
        }
Esempio n. 10
0
        protected virtual void duplicateToAddWeight(SkinnedMesh that, Node thisBone, Node thatBone)
        {
            if (this.m_weightsByBone.ContainsKey(thisBone))
            {
                int[] numArray = this.m_weightsByBone[thisBone];
                if (numArray != null)
                {
                    int length = numArray.Length;
                    for (int firstVertex = 0; firstVertex < length; ++firstVertex)
                    {
                        int weight = numArray[firstVertex];
                        if (weight != 0)
                        {
                            that.addTransform(thatBone, weight, firstVertex, 1);
                        }
                    }
                }
            }
            if ((object)thisBone.GetType() != (object)typeof(Group) && !thisBone.GetType().IsSubclassOf(typeof(Group)))
            {
                return;
            }
            Group group1 = (Group)thisBone;

            if (group1 == null)
            {
                return;
            }
            Group group2     = (Group)thatBone;
            int   childCount = group1.getChildCount();

            for (int index = 0; index < childCount; ++index)
            {
                this.duplicateToAddWeight(that, group1.getChild(index), group2.getChild(index));
            }
        }
Esempio n. 11
0
        private void compileRenderableNodeList(
            ref Node node,
            ref Transform transform,
            int scope,
            int depth)
        {
            if (!node.isRenderingEnabled())
            {
                return;
            }
            Group group = Group.m3g_cast((Object3D)node);

            if (group != null)
            {
                int childCount = group.getChildCount();
                if (transform != null)
                {
                    for (int index = 0; index < childCount; ++index)
                    {
                        Node child = group.getChild(index);
                        if (child.isRenderingEnabled())
                        {
                            this.cachedTransforms[depth].set(transform);
                            child.getCompositeTransformCumulative(ref this.cachedTransforms[depth], depth);
                            this.compileRenderableNodeList(ref child, ref this.cachedTransforms[depth], scope, depth + 1);
                        }
                    }
                }
                else
                {
                    for (int index = 0; index < childCount; ++index)
                    {
                        Node child = group.getChild(index);
                        if (child.isRenderingEnabled())
                        {
                            child.getCompositeTransform(ref this.cachedTransforms[depth]);
                            this.compileRenderableNodeList(ref child, ref this.cachedTransforms[depth], scope, depth + 1);
                        }
                    }
                }
            }
            else
            {
                Mesh mesh = Mesh.m3g_cast((Object3D)node);
                if (mesh == null || (scope & mesh.getScope()) == 0)
                {
                    return;
                }
                bool        skinning    = false;
                SkinnedMesh skinnedMesh = SkinnedMesh.m3g_cast((Object3D)mesh);
                if (skinnedMesh != null)
                {
                    skinning = skinnedMesh != null;
                    if (skinning)
                    {
                        Node skeleton = (Node)skinnedMesh.getSkeleton();
                        skeleton.getCompositeTransform(ref this.cachedTransforms[depth]);
                        if (transform != null)
                        {
                            Transform transform1 = this.m_transformList[this.m_transformListPosition++];
                            transform1.set(transform);
                            transform1.postMultiply(ref this.cachedTransforms[depth]);
                            this.compileRenderableNodeList(ref skeleton, ref transform1, scope, depth + 1);
                        }
                        else
                        {
                            this.compileRenderableNodeList(ref skeleton, ref this.nodeTransform, scope, depth + 1);
                        }
                    }
                }
                Transform transform2 = this.m_transformList[this.m_transformListPosition++];
                if (transform != null)
                {
                    transform2.set(transform);
                }
                else
                {
                    transform2.setIdentity();
                }
                int submeshCount = mesh.getSubmeshCount();
                for (int index = 0; index != submeshCount; ++index)
                {
                    if (mesh.getAppearance(index) != null && mesh.getIndexBuffer(index) != null)
                    {
                        this.m_renderNodeList.Add(new RenderNode((Node)mesh, index, ref transform2, skinning));
                    }
                }
            }
        }
Esempio n. 12
0
 public void addTransform(Node bone, int weight, int firstVertex, int numVertices)
 {
     SkinnedMesh.requireWeightNotZero(weight);
     this.addTransformWithoutWeightCheck(bone, weight, firstVertex, numVertices);
 }