Example #1
0
        private void FillVertexBuffer(SlimDX.Direct3D9.Mesh animationMesh, List<Operations.vVertex> vertexList, int selectedBoneIdx)
        {
            using (DataStream vertexStream = animationMesh.LockVertexBuffer(LockFlags.None))
            {
                Color4 col = new Color4(1f, 1f, 1f);
                for (int i = 0; i < vertexList.Count; i++)
                {
                    Operations.vVertex vertex = vertexList[i];
                    vertexStream.Write(vertex.position.X);
                    vertexStream.Write(vertex.position.Y);
                    vertexStream.Write(vertex.position.Z);
                    if (vertex.boneIndices != null)
                    {
                        vertexStream.Write(vertex.weights[0]);
                        vertexStream.Write(vertex.weights[1]);
                        vertexStream.Write(vertex.weights[2]);
                        vertexStream.Write((byte)vertex.boneIndices[0]);
                        vertexStream.Write((byte)vertex.boneIndices[1]);
                        vertexStream.Write((byte)vertex.boneIndices[2]);
                        vertexStream.Write((byte)vertex.boneIndices[3]);
                    }
                    else
                    {
                        vertexStream.Write((float)0);
                        vertexStream.Write((float)0);
                        vertexStream.Write((float)0);
                        vertexStream.Write((byte)0);
                        vertexStream.Write((byte)0);
                        vertexStream.Write((byte)0);
                        vertexStream.Write((byte)0);
                    }
                    vertexStream.Write(vertex.normal.X);
                    vertexStream.Write(vertex.normal.Y);
                    vertexStream.Write(vertex.normal.Z);
                    if (selectedBoneIdx >= 0)
                    {
                        col.Red = 0f; col.Green = 0f; col.Blue = 0f;
                        int[] boneIndices = vertex.boneIndices;
                        float[] boneWeights = vertex.weights;
                        for (int j = 0; j < boneIndices.Length; j++)
                        {
                            if (boneIndices[j] == 0 && boneWeights[j] == 0)
                            {
                                continue;
                            }

                            int boneIdx = boneIndices[j];
                            if (boneIdx == selectedBoneIdx)
                            {
            /*								switch (cols)
                                {
                                case WeightsColourPreset.Greyscale:
                                    col.r = col.g = col.b = boneWeights[j];
                                    break;
                                case WeightsColourPreset.Metal:
                                    col.r = boneWeights[j] > 0.666f ? 1f : boneWeights[j] * 1.5f;
                                    col.g = boneWeights[j] * boneWeights[j] * boneWeights[j];
                                    break;
                                WeightsColourPreset.Rainbow:*/
                                    if (boneWeights[j] > 0.75f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[j]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[j] > 0.5f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[j]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[j] > 0.25f)
                                    {
                                        col.Red = (boneWeights[j] - 0.25f) * 4f;
                                        col.Green = 1f;
                                        col.Blue = 0f;
                                    }
                                    else
                                    {
                                        col.Green = boneWeights[j] * 4f;
                                        col.Blue = 1f - boneWeights[j] * 4f;
                                    }
            /*									break;
                                }*/
                                break;
                            }
                        }
                    }
                    vertexStream.Write(col.ToArgb());
                    vertexStream.Write(vertex.uv[0]);
                    vertexStream.Write(vertex.uv[1]);
                }
                animationMesh.UnlockVertexBuffer();
            }
        }