示例#1
0
        public VertexArray getSkinWeights()
        {
            this.requireVertexBufferNotNull();
            VertexBuffer vertexBuffer = this.getVertexBuffer();
            VertexArray  skinWeights  = vertexBuffer.getSkinWeights();

            if (skinWeights == null)
            {
                if (this.m_skinWeights == null)
                {
                    VertexArray skinIndices    = this.getSkinIndices();
                    int         componentCount = skinIndices.getComponentCount();
                    int         vertexCount    = vertexBuffer.getVertexCount();
                    this.m_skinWeights = new VertexArray(vertexCount, componentCount, 4);
                    Node[]  boneArray = this.getBoneArray();
                    float[] values    = new float[4];
                    int[]   numArray  = new int[4];
                    float[] src       = new float[4];
                    for (int firstVertex = 0; firstVertex < vertexCount; ++firstVertex)
                    {
                        for (int index = 0; index < componentCount; ++index)
                        {
                            numArray[index] = 0;
                        }
                        skinIndices.get(firstVertex, 1, ref values);
                        int val1 = 0;
                        int num1 = 0;
                        for (int index1 = 0; index1 < 4; ++index1)
                        {
                            int index2 = (int)(sbyte)values[index1] & (int)byte.MaxValue;
                            int weight = this.getWeights(boneArray[index2])[firstVertex];
                            val1             = Math.Min(val1, weight);
                            num1            += Math.Abs(weight);
                            numArray[index1] = weight;
                        }
                        float num2 = 1f;
                        if (num1 > 0)
                        {
                            num2 /= (float)num1;
                        }
                        for (int index = 0; index < componentCount; ++index)
                        {
                            src[index] = num1 <= 0 ? (index != 0 ? 0.0f : 1f) : (float)(numArray[index] - val1) * num2;
                        }
                        this.m_skinWeights.set(firstVertex, 1, src);
                        this.m_vertexBuffer.finalVertexData[firstVertex].skinWeight.X = src[0];
                        this.m_vertexBuffer.finalVertexData[firstVertex].skinWeight.Y = src[1];
                        this.m_vertexBuffer.finalVertexData[firstVertex].skinWeight.Z = src[2];
                        this.m_vertexBuffer.finalVertexData[firstVertex].skinWeight.W = src[3];
                    }
                }
                skinWeights = this.m_skinWeights;
            }
            return(skinWeights);
        }
示例#2
0
        public void preparePositionsForSkinning()
        {
            float[]     scaleBias = new float[4];
            VertexArray positions = this.getVertexBuffer().getPositions(ref scaleBias);

            if (positions.getComponentCount() != 3 || positions.getComponentType() == 4 && (double)scaleBias[0] == 1.0 && ((double)scaleBias[1] == 0.0 && (double)scaleBias[2] == 0.0) && (double)scaleBias[3] == 0.0)
            {
                return;
            }
            float[]     values = new float[positions.getVertexCount() * positions.getComponentCount()];
            VertexArray arr    = new VertexArray(positions.getVertexCount(), positions.getComponentCount(), 4);

            positions.get(0, positions.getVertexCount(), ref values);
            float[] bias = new float[scaleBias.Length - 1];
            Array.Copy((Array)scaleBias, 1, (Array)bias, 0, scaleBias.Length - 1);
            this.getVertexBuffer().setPositions(arr, scaleBias[0], bias);
        }