Esempio n. 1
0
        public static source ArrayToSource(Color[] input, string tag)
        {
            source outputSource = new source();

            outputSource.id = tag;

            const int num_values = 4;

            float_array vectorArray = new float_array();

            vectorArray.Values = new double[input.Length * num_values];
            for (int i = 0; i < input.Length; i++)
            {
                vectorArray.Values[i * num_values + 0] = input[i].r;
                vectorArray.Values[i * num_values + 1] = input[i].g;
                vectorArray.Values[i * num_values + 2] = input[i].b;
                vectorArray.Values[i * num_values + 3] = input[i].a;
            }
            vectorArray.id    = tag + "-array";
            vectorArray.count = (ulong)vectorArray.Values.Length;

            outputSource.Item = vectorArray;

            accessor vectorAccessor = new accessor();

            vectorAccessor.source        = "#" + vectorArray.id;
            vectorAccessor.count         = (ulong)input.Length;
            vectorAccessor.stride        = num_values;
            vectorAccessor.param         = new param[num_values];
            vectorAccessor.param[0]      = new param();
            vectorAccessor.param[0].name = "R";
            vectorAccessor.param[0].type = "float";
            vectorAccessor.param[1]      = new param();
            vectorAccessor.param[1].name = "G";
            vectorAccessor.param[1].type = "float";
            vectorAccessor.param[2]      = new param();
            vectorAccessor.param[2].name = "B";
            vectorAccessor.param[2].type = "float";
            vectorAccessor.param[3]      = new param();
            vectorAccessor.param[3].name = "A";
            vectorAccessor.param[3].type = "float";

            outputSource.technique_common          = new sourceTechnique_common();
            outputSource.technique_common.accessor = vectorAccessor;

            return(outputSource);
        }
Esempio n. 2
0
        public static source ArrayToSource(Color[] input, string tag)
        {
            source outputSource = new source();
            outputSource.id = tag;

            const int num_values = 4;

            float_array vectorArray = new float_array();
            vectorArray.Values = new double[input.Length * num_values];
            for (int i = 0; i < input.Length; i++)
            {
                vectorArray.Values[i * num_values + 0] = input[i].r;
                vectorArray.Values[i * num_values + 1] = input[i].g;
                vectorArray.Values[i * num_values + 2] = input[i].b;
                vectorArray.Values[i * num_values + 3] = input[i].a;
            }
            vectorArray.id = tag + "-array";
            vectorArray.count = (ulong)vectorArray.Values.Length;

            outputSource.Item = vectorArray;

            accessor vectorAccessor = new accessor();
            vectorAccessor.source = "#" + vectorArray.id;
            vectorAccessor.count = (ulong)input.Length;
            vectorAccessor.stride = num_values;
            vectorAccessor.param = new param[num_values];
            vectorAccessor.param[0] = new param();
            vectorAccessor.param[0].name = "R";
            vectorAccessor.param[0].type = "float";
            vectorAccessor.param[1] = new param();
            vectorAccessor.param[1].name = "G";
            vectorAccessor.param[1].type = "float";
            vectorAccessor.param[2] = new param();
            vectorAccessor.param[2].name = "B";
            vectorAccessor.param[2].type = "float";
            vectorAccessor.param[3] = new param();
            vectorAccessor.param[3].name = "A";
            vectorAccessor.param[3].type = "float";

            outputSource.technique_common = new sourceTechnique_common();
            outputSource.technique_common.accessor = vectorAccessor;

            return outputSource;
        }
Esempio n. 3
0
        public static source ArrayToSource(Vector3[] input, string tag)
        {
            source outputSource = new source();

            outputSource.id = tag;

            float_array vectorArray = new float_array();

            vectorArray.Values = new double[input.Length * 3];
            for (int i = 0; i < input.Length; i++)
            {
                vectorArray.Values[i * 3 + 0] = input[i].x;
                vectorArray.Values[i * 3 + 1] = input[i].y;
                vectorArray.Values[i * 3 + 2] = input[i].z;
            }
            vectorArray.id    = tag + "-array";
            vectorArray.count = (ulong)vectorArray.Values.Length;

            outputSource.Item = vectorArray;

            accessor vectorAccessor = new accessor();

            vectorAccessor.source        = "#" + tag + "-array";
            vectorAccessor.count         = (ulong)input.Length;
            vectorAccessor.stride        = 3;
            vectorAccessor.param         = new param[3];
            vectorAccessor.param[0]      = new param();
            vectorAccessor.param[0].name = "X";
            vectorAccessor.param[0].type = "float";
            vectorAccessor.param[1]      = new param();
            vectorAccessor.param[1].name = "Y";
            vectorAccessor.param[1].type = "float";
            vectorAccessor.param[2]      = new param();
            vectorAccessor.param[2].name = "Z";
            vectorAccessor.param[2].type = "float";

            outputSource.technique_common          = new sourceTechnique_common();
            outputSource.technique_common.accessor = vectorAccessor;

            return(outputSource);
        }
Esempio n. 4
0
        public static source ArrayToSource(Vector3[] input, string tag)
        {
            source outputSource = new source();
            outputSource.id = tag;

            float_array vectorArray = new float_array();
            vectorArray.Values = new double[input.Length * 3];
            for (int i = 0; i < input.Length; i++)
            {
                vectorArray.Values[i * 3 + 0] = input[i].x;
                vectorArray.Values[i * 3 + 1] = input[i].y;
                vectorArray.Values[i * 3 + 2] = input[i].z;
            }
            vectorArray.id = tag + "-array";
            vectorArray.count = (ulong)vectorArray.Values.Length;

            outputSource.Item = vectorArray;

            accessor vectorAccessor = new accessor();
            vectorAccessor.source = "#" + tag + "-array";
            vectorAccessor.count = (ulong)input.Length;
            vectorAccessor.stride = 3;
            vectorAccessor.param = new param[3];
            vectorAccessor.param[0] = new param();
            vectorAccessor.param[0].name = "X";
            vectorAccessor.param[0].type = "float";
            vectorAccessor.param[1] = new param();
            vectorAccessor.param[1].name = "Y";
            vectorAccessor.param[1].type = "float";
            vectorAccessor.param[2] = new param();
            vectorAccessor.param[2].name = "Z";
            vectorAccessor.param[2].type = "float";

            outputSource.technique_common = new sourceTechnique_common();
            outputSource.technique_common.accessor = vectorAccessor;

            return outputSource;
        }
Esempio n. 5
0
        protected mesh CreatePalletMesh(PalletProperties palletProperties)
        {
            // build pallet object
            Pallet pallet = new Pallet(palletProperties);
            // build list of boxes
            List<Box> listBoxes = pallet.BuildListOfBoxes();
            // build list of vertices / normals / UVs
            ulong vertexCount = 0, normalCount = 0, uvCount = 0, triangleCount = 0, boxCount = 0;
            string triangle_string = string.Empty;

            List<double> doubleArrayPosition = new List<double>(), doubleArrayNormal = new List<double>(), doubleArrayUV = new List<double>();

            foreach (Box box in listBoxes)
            {
                foreach (Vector3D p in box.Points)
                {
                    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;
                }
                foreach (TriangleIndices tr in box.Triangles)
                {
                    triangle_string += tr.ConvertToString(boxCount);
                    ++triangleCount;
                }
                ++boxCount;
            }
            mesh palletMesh = new mesh();

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

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

            // uv source
            source palletPositionUV = new source() { id = "pallet_UV", name = "pallet_UV" };
            float_array farrayUV = new float_array { id = "pallet_UV_float_array", count = (ulong)doubleArrayUV.Count, Values = doubleArrayUV.ToArray() };
            palletPositionUV.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 2,
                    count = vertexCount,
                    source = "#pallet_UV_float_array",
                    param = new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } }
                }
            };
            palletPositionUV.Item = farrayUV;
            // insert sources
            palletMesh.source = new source[] { palletPositionSource, palletPositionNormal, palletPositionUV };

            // vertices
            InputLocal verticesInput = new InputLocal() { semantic = "POSITION", source = "#pallet_position" };
            palletMesh.vertices = new vertices() { id = "pallet_vertex", input = new InputLocal[] { verticesInput } };

            triangles trianglesPallet = new triangles() { material = "materialPallet", count = triangleCount };
            trianglesPallet.input = new InputLocalOffset[]
                                    {
                                        new InputLocalOffset() { semantic="VERTEX", source="#pallet_vertex", offset=0}
                                        , new InputLocalOffset() { semantic="NORMAL", source="#pallet_normal", offset=1}
                                        , new InputLocalOffset() { semantic="TEXCOORD", source="#pallet_UV", offset=2, set=0, setSpecified=true }
                                    };

            trianglesPallet.p = triangle_string;
            palletMesh.Items = new object[] { trianglesPallet };

            return palletMesh;
        }
Esempio n. 6
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;
        }