Exemple #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;
        }
            public override fMesh MakeGeometry(AxisGizmoFlags widget)
            {
                switch (widget)
                {
                case AxisGizmoFlags.AxisTranslateY:
                    if (MyAxisTranslateY == null)
                    {
                        Radial3DArrowGenerator arrowGen = new Radial3DArrowGenerator()
                        {
                            HeadLength = 2.0f, TipRadius = 0.1f, StickLength = 1.5f, Clockwise = true
                        };
                        DMesh3 mesh = arrowGen.Generate().MakeDMesh();
                        MeshNormals.QuickCompute(mesh);
                        MeshTransforms.Translate(mesh, 0.5 * Vector3d.AxisY);
                        DMesh3 flip = new DMesh3(mesh);
                        MeshTransforms.Rotate(flip, Vector3d.Zero, Quaterniond.AxisAngleD(Vector3d.AxisX, 180));
                        MeshEditor.Append(mesh, flip);
                        MyAxisTranslateY = new fMesh(mesh);
                    }
                    return(MyAxisTranslateY);

                default:
                    return(null);
                }
            }
Exemple #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <IGH_Goo> X = new List <IGH_Goo>();

            if (!DA.GetDataList(0, X))
            {
                return;
            }

            ThreeJS tJS = new ThreeJS();


            tJS.SetHeader(new Header());
            tJS.SetFooter(new Footer());

            int          i      = 0;
            List <wMesh> Meshes = new List <wMesh>();

            foreach (IGH_Goo Obj in X)
            {
                wMesh M = new wMesh();
                Obj.CastTo(out M);

                fMesh tMesh = new fMesh(M);
                tMesh.BuildThreeGeometry(i);
                tJS.AddGeometry(tMesh);
                i += 1;
            }
            tJS.Assemble();
            DA.SetData(0, tJS);
        }