Example #1
0
        public List <SyncMesh> BuildMeshAry()
        {
            List <SyncMesh> meshAry = new List <SyncMesh>();

            for (int i = 0; i < obj.MeshList.Count; i++)
            {
                Obj curObj = obj.MeshList[i];

                // Create a hardcoded quad mesh
                SyncMesh syncmesh = new SyncMesh(new SyncId(curObj.Name), curObj.Name);

                foreach (ObjParser.Types.Vertex vertex in curObj.VertexList)
                {
                    syncmesh.Vertices.Add(new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z));
                }

                foreach (ObjParser.Types.Vertex normal in curObj.VertexList)
                {
                    syncmesh.Normals.Add(new Vector3(0, 0, 1));
                }

                foreach (ObjParser.Types.TextureVertex uv in curObj.TextureList)
                {
                    syncmesh.Uvs.Add(new Vector2((float)uv.X, (float)uv.Y));
                }

                meshAry.Add(syncmesh);
            }

            return(meshAry);
        }
Example #2
0
        SyncObject BuildObject(SyncMesh mesh, SyncMaterial material)
        {
            // Create a parent object
            var parentObject = new SyncObject(new SyncId("Parent id"), "Quad Object Parent")
            {
                Transform = SyncTransform.Identity
            };

            // Create a child object with geometry
            var childObject = new SyncObject(new SyncId("Child id"), "Quad Object Child")
            {
                MeshId      = mesh.Id,
                MaterialIds = new List <SyncId> {
                    material.Id
                },
                Transform = SyncTransform.Identity
            };

            parentObject.Children.Add(childObject);

            // Fill the object with metadata
            parentObject.Metadata.Add("Key 1", new SyncParameter("Value", "Group", true));
            parentObject.Metadata.Add("Key 2", new SyncParameter("Other value", "Group", true));
            parentObject.Metadata.Add("名前", new SyncParameter("テストデータくん", "Group", true));

            // Uncomment the following line to add the "Merge" metadata key.
            // Because of the rules.json file, this would trigger the MergeChildObjects action.
            //parentObject.Metadata.Add("Merge", new SyncParameter("", "Rules", true));

            return(parentObject);
        }
Example #3
0
        public SyncMesh BuildMesh(Obj curObj)
        {
            SyncMesh syncmesh = new SyncMesh(new SyncId("MeshId_" + curObj.Name), "Mesh_" + curObj.Name);

            // Faceの定義に従う。無駄は多くなる
            syncmesh.SubMeshes = new List <SyncSubMesh>();
            SyncSubMesh submesh = new SyncSubMesh();

            for (int j = 0; j < curObj.FaceList.Count; j++)
            {
                ObjParser.Types.Face face = curObj.FaceList[j];

                for (int i = 0; i < face.VertexIndexList.Length; i++)
                {
                    //idx
                    int vertexIdx = face.VertexIndexList[i] - 1;
                    int uvIdx     = face.TextureVertexIndexList[i] - 1;
                    int normalIdx = face.NormalIndexList[i] - 1;
                    //Console.WriteLine(string.Format("index[{0}] vert[{1}] uv[{2}] normal[{3}]",i, vertexIdx+1, uvIdx+1, normalIdx+1));

                    //ObjParser.Types.Vertex vertex = curObj.VertexList[vertexIdx];
                    //ObjParser.Types.TextureVertex uv = curObj.TextureList[uvIdx];
                    //ObjParser.Types.VertexNormal normal = curObj.VertexNormalList[normalIdx];
                    ObjParser.Types.Vertex        vertex = obj.VertexList[vertexIdx];
                    ObjParser.Types.TextureVertex uv     = obj.TextureList[uvIdx];
                    ObjParser.Types.VertexNormal  normal = obj.VertexNormalList[normalIdx];

                    //頂点
                    // OpenGL->DirectX変換のため、Xは反転する
                    syncmesh.Vertices.Add(new Vector3(vertex.X * -1.0f, vertex.Y, vertex.Z)); // 2021.5.26 X軸を反転
                    syncmesh.Uvs.Add(new Vector2(uv.X, uv.Y));
                    syncmesh.Normals.Add(new Vector3(normal.X * -1.0f, normal.Y, normal.Z));  // 2021.5.26 X軸を反転
                    //syncmesh.Normals.Add(new Vector3(0,0,1));
                    //Console.WriteLine(string.Format("vert={0}\t{1}\t{2}", (float)vertex.X, (float)vertex.Y, (float)vertex.Z));

                    //index
                    //submesh.Triangles.Add(i + j * face.VertexIndexList.Length);
                    // OpenGL->DirectX変換のため、逆順でセットする
                    submesh.Triangles.Add((face.VertexIndexList.Length - 1 - i) + j * face.VertexIndexList.Length);
                }
            }
            syncmesh.SubMeshes.Add(submesh);

            return(syncmesh);
        }
Example #4
0
        public SyncMesh BuildMesh_Legacy(Obj curObj)
        {
            SyncMesh syncmesh = new SyncMesh(new SyncId("MeshId_" + curObj.Name), "Mesh_" + curObj.Name);

            foreach (ObjParser.Types.Vertex vertex in curObj.VertexList)
            {
                syncmesh.Vertices.Add(new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z));
            }

            foreach (ObjParser.Types.VertexNormal normal in curObj.VertexNormalList)
            {
                syncmesh.Normals.Add(new Vector3((float)normal.X, (float)normal.Y, (float)normal.Z));
            }

            foreach (ObjParser.Types.TextureVertex uv in curObj.TextureList)
            {
                syncmesh.Uvs.Add(new Vector2((float)uv.X, (float)uv.Y));
            }

            syncmesh.SubMeshes = new List <SyncSubMesh>();
            SyncSubMesh submesh = new SyncSubMesh();

            foreach (ObjParser.Types.Face face in curObj.FaceList)
            {
                //string[] line = face.ToString().Split(' ');
                //foreach (string data in line)
                //{
                //    string[] facegeom = data.Split('/');
                //    int result = 0;
                //    if (int.TryParse(data, out result))
                //    {
                //        submesh.Triangles.Add(result);
                //    }
                //}
                foreach (int idx in face.VertexIndexList)
                {
                    submesh.Triangles.Add(idx);
                }
            }
            syncmesh.SubMeshes.Add(submesh);

            return(syncmesh);
        }
Example #5
0
        public SyncObject BuildObject(SyncMesh mesh, SyncMaterial material, int idx)
        {
            // Create a parent object
            var parentObject = new SyncObject(new SyncId("ParentId_") + mesh.Id.ToString(), "ObjectParent_" + mesh.Name)
            {
                Transform = SyncTransform.Identity
            };

            // Create a child object with geometry
            var childObject = new SyncObject(new SyncId("ChildId_") + mesh.Id.ToString(), "ObjectChild_" + mesh.Name)
            {
                MeshId      = mesh.Id,
                MaterialIds = new List <SyncId> {
                    material.Id
                },
                Transform = SyncTransform.Identity
            };

            parentObject.Children.Add(childObject);

            // Fill the object with metadata
            parentObject.Metadata.Add("Key 1", new SyncParameter("Value", "Group", true));
            parentObject.Metadata.Add("Key 2", new SyncParameter("Other value", "Group", true));
            parentObject.Metadata.Add("メッシュID", new SyncParameter(mesh.Id.ToString(), "Group", true));
            parentObject.Metadata.Add("マテリアルID", new SyncParameter(material.Id.ToString(), "Group", true));

            parentObject.Metadata.Add("図形名", new SyncParameter(obj.MeshList[idx].Name, "Group", true));
            parentObject.Metadata.Add("マテリアル名", new SyncParameter(obj.MeshList[idx].UseMtl, "Group", true));
            parentObject.Metadata.Add("頂点数", new SyncParameter(obj.MeshList[idx].VertexList.Count.ToString(), "Group", true));

            parentObject.Metadata.Add("ポリゴン数", new SyncParameter(mesh.TriangleCount.ToString(), "Group", true));

            // Uncomment the following line to add the "Merge" metadata key.
            // Because of the rules.json file, this would trigger the MergeChildObjects action.
            //parentObject.Metadata.Add("Merge", new SyncParameter("", "Rules", true));

            return(parentObject);
        }
Example #6
0
        void PerformExportTransaction()
        {
            // Report the progress of the export to 0%
            m_PublisherClient.ReportProgress(0);

            // Start a transaction ; note that the publisher client can only run one transaction at a time.
            PublisherTransaction transaction = m_PublisherClient.StartTransaction();

            // add sample plane //
            {
                // Build a SyncMesh and send it to the server
                var mesh = BuildMesh();
                transaction.Send(mesh);

                // Build a SyncMaterial and send it to the server
                var material = BuildMaterial(SyncColor.White);
                transaction.Send(material);

                // Report in between parsing progress
                m_PublisherClient.ReportProgress(50);

                // Build a SyncObject and send it to the server.
                var obj = BuildObject(mesh, material);
                transaction.Send(obj);

                // Build a SyncObjectInstance and send it to the server
                var instance = BuildObjectInstance(obj);
                transaction.Send(instance);
            }
            // add sample plane //

            // objファイルを開く //
            DataUtil meshData = new DataUtil();

            meshData.fileName = @"D:\model\house.obj";
            meshData.OpenObj(@"D:\model\house.obj");

            int num = meshData.obj.MeshList.Count;

            for (int i = 0; i < num; i++)
            {
                ObjParser.Obj currentObj = meshData.obj.MeshList[i];
                Console.WriteLine("Mesh: " + currentObj.Name);

                SyncMesh mesh = meshData.BuildMesh(currentObj);
                transaction.Send(mesh);
                Console.WriteLine("\tMesh Id: " + mesh.Id);
                Console.WriteLine("\tMesh Name: " + mesh.Name);

                SyncMaterial material = meshData.BuildMaterial(currentObj, transaction);
                transaction.Send(material);
                Console.WriteLine("\tMaterial Id: " + material.Id);
                Console.WriteLine("\tMaterial Name: " + material.Name);

                // Report in between parsing progress
                m_PublisherClient.ReportProgress(i * num / 100);

                // Build a SyncObject and send it to the server.
                var obj = meshData.BuildObject(mesh, material, i);
                transaction.Send(obj);
                Console.WriteLine("\tObject Id: " + obj.Id);
                Console.WriteLine("\tObject Name: " + obj.Name);

                // Build a SyncObjectInstance and send it to the server
                var instance = meshData.BuildObjectInstance(obj);
                transaction.Send(instance);
                Console.WriteLine("\tObject Instance Id: " + instance.Id);
                Console.WriteLine("\tObject Instance Name: " + instance.Name);
            }

#if false
            for (int i = 0; i < meshData.obj.MeshList.Count; i++)
            {
                List <SyncMesh> meshAry = meshData.BuildMesh();
                foreach (SyncMesh mesh in meshAry)
                {
                    transaction.Send(mesh);
                }

                List <SyncMaterial> materialAry = meshData.BuildMaterial();
                foreach (SyncMaterial material in materialAry)
                {
                    transaction.Send(material);
                }

                // Report in between parsing progress
                //m_PublisherClient.ReportProgress(50);

                // Build a SyncObject and send it to the server.
                foreach (SyncMesh mesh in meshAry)
                {
                    var obj = meshData.BuildObject(mesh);
                    transaction.Send(obj);

                    // Build a SyncObjectInstance and send it to the server
                    var instance = meshData.BuildObjectInstance(obj);
                    transaction.Send(instance);
                }
            }
#endif

            // Commit the transaction, then detach it from the publisher client.
            transaction.Commit();

            // Report the completion of the export
            m_PublisherClient.ReportProgress(100);
        }