Beispiel #1
0
        protected mesh CreateCaseMesh(BoxProperties caseProperties)
        {
            // build box
            Box box = new Box(0, caseProperties);
            // build list of vertices / normals / UVs
            ulong vertexCount = 0, normalCount = 0, uvCount = 0;
            List<double> doubleArrayPosition = new List<double>(), doubleArrayNormal = new List<double>(), doubleArrayUV = new List<double>();
            foreach (Vector3D p in box.PointsSmallOffset)
            {
                doubleArrayPosition.Add(p.X); doubleArrayPosition.Add(p.Y); doubleArrayPosition.Add(p.Z);
                ++vertexCount;
            }
            foreach (Vector3D n in box.Normals)
            {
                doubleArrayNormal.Add(n.X); doubleArrayNormal.Add(n.Y); doubleArrayNormal.Add(n.Z);
                ++normalCount;
            }
            foreach (Vector2D uv in box.UVs)
            {
                doubleArrayUV.Add(uv.X); doubleArrayUV.Add(uv.Y);
                ++uvCount;
            }

            mesh caseMesh = new mesh();

            // position source
            source casePositionSource = new source() { id = "case_position", name = "case_position" };
            float_array farrayPosition = new float_array { id = "case_position_float_array", count = (ulong)doubleArrayPosition.Count, Values = doubleArrayPosition.ToArray() };
            casePositionSource.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 3,
                    count = vertexCount,
                    source = "#case_position_float_array",
                    param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } }
                }
            };
            casePositionSource.Item = farrayPosition;

            // normal source
            source casePositionNormal = new source() { id = "case_normal", name = "case_normal" };
            float_array farrayNormal = new float_array { id = "case_normal_float_array", count = (ulong)doubleArrayNormal.Count, Values = doubleArrayNormal.ToArray() };
            casePositionNormal.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 3,
                    count = normalCount,
                    source = "#case_normal_float_array",
                    param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } }
                }
            };
            casePositionNormal.Item = farrayNormal;

            // uv source
            source casePositionUV = new source() { id = "case_UV", name = "pallet_UV" };
            float_array farrayUV = new float_array { id = "case_UV_float_array", count = (ulong)doubleArrayUV.Count, Values = doubleArrayUV.ToArray() };
            casePositionUV.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 2,
                    count = vertexCount,
                    source = "#case_UV_float_array",
                    param = new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } }
                }
            };
            casePositionUV.Item = farrayUV;
            // insert sources
            caseMesh.source = new source[] { casePositionSource, casePositionNormal, casePositionUV };

            // vertices
            InputLocal verticesInput = new InputLocal() { semantic = "POSITION", source = "#case_position" };
            caseMesh.vertices = new vertices() { id = "case_vertex", input = new InputLocal[] { verticesInput } };

            List<object> trianglesList = new List<object>();

            // build list of triangles
            foreach (HalfAxis.HAxis axis in HalfAxis.All)
            {
                triangles trianglesCase = new triangles() { material = string.Format("materialCase{0}", (uint)axis), count = 2 };
                trianglesCase.input = new InputLocalOffset[]
                                    {
                                        new InputLocalOffset() { semantic="VERTEX", source="#case_vertex", offset=0}
                                        , new InputLocalOffset() { semantic="NORMAL", source="#case_normal", offset=1}
                                        , new InputLocalOffset() { semantic="TEXCOORD", source="#case_UV", offset=2, set=0, setSpecified=true }
                                    };
                string triangle_string = string.Empty;
                foreach (TriangleIndices tr in box.TrianglesByFace(axis))
                    triangle_string += tr.ConvertToString(0);
                trianglesCase.p = triangle_string;
                trianglesList.Add(trianglesCase);
            }
            // build list of lines
            lines linesCase = new lines()
            {
                material = "materialCaseLines",
                count = 12,
                input = new InputLocalOffset[]
                {
                    new InputLocalOffset() { semantic="VERTEX", source="#case_vertex", offset=0}
                },
                p = "0 1 1 2 2 3 3 0 4 5 5 6 6 7 7 4 0 4 1 5 2 6 3 7"
            };
            trianglesList.Add(linesCase);

            caseMesh.Items = trianglesList.ToArray();
            return caseMesh;
        }