コード例 #1
0
ファイル: Geometry.cs プロジェクト: chantsunman/SharpDX_Demo
        //Constructor
        internal Geometry(SharpDevice device, ModelGeometry data, bool animated)
        {
            this.Name = data.Name;
            this.Device = device;

            //Data
            List<VertexFormat> vertices = new List<VertexFormat>(data.Vertices);

            List<int> indices = new List<int>(data.Indices);

            VertexCount = vertices.Count;
            IndexCount = indices.Count;

            //Vertex Buffer
            VertexBuffer = SharpDX.Direct3D11.Buffer.Create<VertexFormat>(Device.Device, BindFlags.VertexBuffer, vertices.ToArray());

            //Index Buffer
            IndexBuffer = SharpDX.Direct3D11.Buffer.Create<int>(Device.Device, BindFlags.IndexBuffer, indices.ToArray());

            Material = new Material(data.Material);

            IsAnimated = animated;

            transformBuffer = new Buffer11(Device.Device, Utilities.SizeOf<SkinShaderInformation>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            paletteBuffer = new Buffer11(Device.Device, Utilities.SizeOf<Matrix>() * 256, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
コード例 #2
0
ファイル: Geometry.cs プロジェクト: yu2373536/SharpDX_Demo
        //Constructor
        internal Geometry(SharpDevice device, ModelGeometry data, bool animated)
        {
            this.Name   = data.Name;
            this.Device = device;

            //Data
            List <VertexFormat> vertices = new List <VertexFormat>(data.Vertices);

            List <int> indices = new List <int>(data.Indices);

            VertexCount = vertices.Count;
            IndexCount  = indices.Count;

            //Vertex Buffer
            VertexBuffer = SharpDX.Direct3D11.Buffer.Create <VertexFormat>(Device.Device, BindFlags.VertexBuffer, vertices.ToArray());

            //Index Buffer
            IndexBuffer = SharpDX.Direct3D11.Buffer.Create <int>(Device.Device, BindFlags.IndexBuffer, indices.ToArray());


            Material = new Material(data.Material);

            IsAnimated = animated;


            transformBuffer = new Buffer11(Device.Device, Utilities.SizeOf <SkinShaderInformation>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            paletteBuffer   = new Buffer11(Device.Device, Utilities.SizeOf <Matrix>() * 256, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
        }
コード例 #3
0
        private static List<ModelGeometry> LoadGeometries(XElement geometryNode, SemanticAssociations association, List<Vector4> weights = null, List<Vector4> joints = null)
        {
            List<ModelGeometry> geometries = new List<ModelGeometry>();

            //geometry
            if (geometryNode.GetNode("mesh") != null)
            {
                //if mesh load data
                var mesh = geometryNode.GetNode("mesh");

                var sources = mesh.GetNodes("source");
                var vertices = mesh.GetNodes("vertices");

                //load data, only triangles supported

                foreach (var elem in mesh.Elements())
                {
                    ModelGeometry geometry = new ModelGeometry();
                    geometry.Name = geometryNode.GetAttribute("id");
                    //lines
                    //linestrips
                    switch (elem.Name.LocalName)
                    {
                        case "polygons":
                            break;
                        case "polylist":
                            break;
                        case "triangles":
                            GetTriangleMesh(geometry, elem, mesh, association, weights, joints);
                            geometry.Optimize();
                            geometries.Add(geometry);
                            break;
                        case "trifans":
                            break;
                        case "tristrips":
                            break;
                        default:
                            break;
                    }

                }

            }

            return geometries;
        }
コード例 #4
0
        //Load Triangle Mesh
        private static void GetTriangleMesh(ModelGeometry model, XElement triangle, XElement mesh, SemanticAssociations association, List<Vector4> weights = null, List<Vector4> joints = null)
        {
            //Indices
            List<int> indices = GetIntList(triangle.GetNode("p").Value);

            //Load Channel
            var inputs = triangle.GetNodes("input");
            List<ChannelData> inputData = new List<ChannelData>();
            foreach (XElement elem in inputs)
            {
                inputData.Add(new ChannelData(elem));

            }

            //Load Material
            model.Material = new MaterialData();
            model.Material = GetMaterial(triangle.Document, triangle.GetAttribute("material"));

            //Create Vertices
            int k = 0;
            while (k < indices.Count)
            {
                VertexFormat v = new VertexFormat();

                foreach (ChannelData e in inputData)
                {
                    var data = e.GetChannel(indices[k]);

                    switch (association[e.Semantic])
                    {
                        case ChannelCode.Position:
                            v.Position = new Vector3(data);

                            //Add weights and joints if loaded for skinned model
                            if (weights != null)
                            {
                                v.Weight = weights[indices[k]];
                            }

                            if (joints != null)
                            {
                                v.Joint = joints[indices[k]];
                            }

                            break;
                        case ChannelCode.Normal:
                            v.Normal = new Vector3(data);
                            break;
                        case ChannelCode.Tangent:
                            v.Tangent = new Vector3(data);
                            break;
                        case ChannelCode.Binormal:
                            v.Binormal = new Vector3(data);
                            break;
                        case ChannelCode.TexCoord1:
                            if (data.Length >= 2)
                                v.TextureSet1 = new Vector2(data.Take(2).ToArray());
                            break;
                        case ChannelCode.TexCoord2:
                            v.TextureSet2 = new Vector2(data.Take(2).ToArray());
                            break;
                        case ChannelCode.Joint:
                            v.Joint = new Vector4(data);
                            break;
                        case ChannelCode.Weight:
                            v.Weight = new Vector4(data);
                            break;
                        case ChannelCode.None:

                            break;
                        default:
                            break;
                    }

                    k++;
                }

                //Save to model
                model.Vertices.Add(v);
                model.Indices.Add(model.Indices.Count);
            }
        }