Example #1
0
        // update visible triangles for this chunk
        void update_triangles(OrderedChunk chunk, float max_scalar)
        {
            if (chunk.mesh == null)
            {
                chunk.mesh = new MeshChunk();
            }

            int count = 0;

            foreach (int idx in chunk.order_range)
            {
                if (tri_ordering[idx].scalar < max_scalar)
                {
                    count++;
                }
            }

            // if we have the same count, we can keep it
            if (chunk.mesh.current_count == count)
            {
                chunk.mesh.submesh.SetVisible(true);
                return;
            }

            // find subset triangles
            int[] triangles = new int[count];
            for (int k = 0; k < count; ++k)
            {
                int idx = chunk.order_range.a + k;
                triangles[k] = tri_ordering[idx].tid;
            }

            // find submesh
            // [TODO] faster variant of this? Also could be computing these in background...
            DSubmesh3 submesh = new DSubmesh3(Mesh, triangles);

            MeshTransforms.VertexNormalOffset(submesh.SubMesh, NormalOffsetDistance);
            fMesh umesh = UnityUtil.DMeshToUnityMesh(submesh.SubMesh, false);

            // create or update GO
            if (chunk.mesh.submesh == null)
            {
                chunk.mesh.submesh = new fMeshGameObject(umesh, true, false);
                if (ChunkMeshMaterial != null)
                {
                    chunk.mesh.submesh.SetMaterial(ChunkMeshMaterial);
                }
                if (ChunkMeshParent != null)
                {
                    ChunkMeshParent.AddChild(chunk.mesh.submesh, false);
                }
            }
            else
            {
                chunk.mesh.submesh.UpdateMesh(umesh, true, false);
            }

            chunk.mesh.submesh.SetVisible(true);
            chunk.mesh.current_count = count;
        }
Example #2
0
        public void Create(SOMaterial useMaterial, fGameObject parent)
        {
            if (curve == null)
            {
                curve = new DCurve3();
            }

            meshObject = GameObjectFactory.CreateMeshGO("mesh_tube_preview");
            //meshObject.SetMesh(new fMesh())
            meshObject.SetMaterial(MaterialUtil.ToMaterialf(useMaterial));
            bUpdatePending = true;

            parent.AddChild(meshObject, false);
        }
Example #3
0
        void validate_tube_meshes()
        {
            Polygon2d circle = Polygon2d.MakeCircle(Radius, Slices);

            for (int i = 0; i < CurveSet.Length; ++i)
            {
                TubeGenerator gen = new TubeGenerator(CurveSet[i].curve, circle)
                {
                    NoSharedVertices = false
                };
                gen.Generate();
                CurveSet[i].tubeMeshGO = GameObjectFactory.CreateMeshGO("tube_" + i.ToString(),
                                                                        gen.MakeUnityMesh(), false, true);
                CurveSet[i].tubeMeshGO.SetMaterial(curveMaterial, true);
                parentGO.AddChild(CurveSet[i].tubeMeshGO, false);
            }
        }