/// <summary>
        /// compute offset meshes as simple extrusions
        /// </summary>
        void compute_offset_meshes_nosdf()
        {
            if (cached_inner_sdf_offset != inner_offset)
            {
                InnerOffsetMesh = new DMesh3(cachedInputMesh);
                MeshTransforms.FromFrame(InnerOffsetMesh, cachedInputsTransform);

                MeshNormals.QuickCompute(InnerOffsetMesh);
                MeshTransforms.VertexNormalOffset(InnerOffsetMesh, inner_offset);
                Reducer reducer = new Reducer(InnerOffsetMesh);
                reducer.ReduceToTriangleCount(5000);
                InnerOffsetMeshSpatial  = new DMeshAABBTree3(InnerOffsetMesh, true);
                cached_inner_sdf_offset = inner_offset;
            }

            double max_offset = inner_offset + thickness;

            if (cached_outer_sdf_offset != max_offset)
            {
                OuterOffsetMesh = new DMesh3(cachedInputMesh);
                MeshTransforms.FromFrame(OuterOffsetMesh, cachedInputsTransform);

                MeshNormals.QuickCompute(OuterOffsetMesh);
                MeshTransforms.VertexNormalOffset(OuterOffsetMesh, max_offset);
                Reducer reducer = new Reducer(OuterOffsetMesh);
                reducer.ReduceToTriangleCount(5000);
                OuterOffsetMeshSpatial  = new DMeshAABBTree3(OuterOffsetMesh, true);
                cached_outer_sdf_offset = max_offset;
            }

            //Util.WriteDebugMesh(MeshSource.GetIMesh(), "c:\\scratch\\__OFFESTS_orig.obj");
            //Util.WriteDebugMesh(InnerOffsetMesh, "c:\\scratch\\__OFFESTS_inner.obj");
            //Util.WriteDebugMesh(OuterOffsetMesh, "c:\\scratch\\__OFFESTS_outer.obj");
        }
Esempio n. 2
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;
        }