Esempio n. 1
0
            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);
                }
            }
        public override bool BuildOnMesh(DMesh3Builder meshBuilder)
        {
            var doorCopy = new DMesh3(Mesh, bCompact: true);

            if (FrontNormal == -Vector3d.AxisZ)
            {
                // trick to prevent 180 rotation
                FrontNormal += new Vector3d(0.0000001, 0.0, 0.0);
            }

            var meshWidth  = doorCopy.GetBounds().Width;
            var meshHeight = doorCopy.GetBounds().Height;

            var widthScale  = WidthLimit / meshWidth;
            var heightScale = HeightLimit / meshHeight;

            Quaterniond orientingQuaternion = new Quaterniond(Vector3d.AxisZ, FrontNormal);

            MeshTransforms.Rotate(doorCopy, Vector3d.Zero, orientingQuaternion);
            MeshTransforms.Scale(doorCopy, Math.Min(widthScale, heightScale));
            MeshTransforms.Translate(doorCopy, Origin);

            meshBuilder.AppendNewMesh(doorCopy);
            meshBuilder.SetActiveMesh(0);
            return(true);
        }
Esempio n. 3
0
        void update_hole_mesh()
        {
            CappedCylinderGenerator cylgen = new CappedCylinderGenerator()
            {
                BaseRadius = 0.5f, TopRadius = 0.5f, Height = 1, Slices = this.subdivisions,
                Clockwise  = true
            };
            DMesh3 mesh = cylgen.Generate().MakeDMesh();

            MeshTransforms.Rotate(mesh, Vector3d.Zero, Quaterniond.AxisAngleD(Vector3d.AxisX, 90));
            CavityPreviewSO.ReplaceMesh(mesh, true);
        }
Esempio n. 4
0
        public void Transform(Vector3D axis, double angle)
        {
            Vector3d    _axis    = new Vector3d(axis.X, axis.Y, axis.Z);
            Quaterniond rotation = new Quaterniond(_axis, angle);

            MeshTransforms.Rotate(_mesh, new Vector3d(0, 0, 0), rotation);
            if (_smoothMesh != null)
            {
                MeshTransforms.Rotate(_smoothMesh, new Vector3d(0, 0, 0), rotation);
                _displayMesh = DMeshToMeshGeometry(_smoothMesh);
            }
            else
            {
                _displayMesh = DMeshToMeshGeometry(_mesh);
            }
        }
Esempio n. 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;
            double     rot      = 0;
            Plane      plane    = Plane.WorldXY;

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref rot);
            DA.GetData(2, ref plane);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            Quaterniond quat = new Quaterniond(plane.ZAxis.ToVec3d(), rot);

            MeshTransforms.Rotate(dMsh_copy, plane.Origin.ToVec3d(), quat);

            DA.SetData(0, dMsh_copy);
        }
Esempio n. 6
0
        public void ResetRotations()
        {
            Vector3d origin = new Vector3d(0, 0, 0);

            //x axis reset
            Quaterniond rotation = new Quaterniond(new Vector3d(1, 0, 0), 0);

            MeshTransforms.Rotate(_mesh, origin, rotation);

            if (_smoothMesh != null)
            {
                MeshTransforms.Rotate(_smoothMesh, new Vector3d(0, 0, 0), rotation);
            }

            //y axis reset
            rotation = new Quaterniond(new Vector3d(0, 1, 0), 0);
            MeshTransforms.Rotate(_mesh, origin, rotation);

            if (_smoothMesh != null)
            {
                MeshTransforms.Rotate(_smoothMesh, new Vector3d(0, 0, 0), rotation);
            }

            //z axis reset
            rotation = new Quaterniond(new Vector3d(0, 0, 1), 0);
            MeshTransforms.Rotate(_mesh, origin, rotation);

            if (_smoothMesh != null)
            {
                MeshTransforms.Rotate(_smoothMesh, new Vector3d(0, 0, 0), rotation);
            }

            if (_smoothMesh != null)
            {
                _displayMesh = DMeshToMeshGeometry(_smoothMesh);
            }
            else
            {
                _displayMesh = DMeshToMeshGeometry(_mesh);
            }
        }
        public override bool BuildOnMesh(DMesh3Builder meshBuilder)
        {
            DMesh3 windowCopy = null;

            BuildingTask = Task.Run(() =>
            {
                windowCopy = new DMesh3(Mesh, bCompact: true);
                //var windowCopy = Mesh;
                if (FrontNormal == -Vector3d.AxisZ)
                {
                    // trick to prevent 180 rotation
                    FrontNormal += new Vector3d(0.0000001, 0.0, 0.0);
                }

                var meshWidth  = windowCopy.GetBounds().Width;
                var meshHeight = windowCopy.GetBounds().Height;

                var widthScale    = WidthLimit / meshWidth;
                var heightScale   = HeightLimit / meshHeight;
                var selectedScale = Math.Min(widthScale, heightScale);

                Quaterniond orientingQuaternion = new Quaterniond(Vector3d.AxisZ, FrontNormal);
                MeshTransforms.Rotate(windowCopy, Vector3d.Zero, orientingQuaternion);

                MeshTransforms.Scale(windowCopy, selectedScale);

                MeshTransforms.Translate(windowCopy, Origin);
                //MeshTransforms.Translate(windowCopy, Origin + Vector3d.AxisY * meshHeight * selectedScale * 0.6);
            }).ContinueWith(t =>
            {
                lock (meshBuilder)
                {
                    meshBuilder.AppendNewMesh(windowCopy);
                    meshBuilder.SetActiveMesh(0);
                }
            });

            return(true);
        }
        override protected void BuildGizmo()
        {
            gizmo.SetName("SurfaceConstrainedGizmo");

            make_materials();

            centerGO = AppendMeshGO("object_origin",
                                    UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere), srcMaterial, gizmo);
            centerGO.SetLocalScale(WidgetScale);

            Widgets[centerGO] = new SurfaceConstrainedPointWidget(this, this.parentScene)
            {
                RootGameObject = centerGO, StandardMaterial = srcMaterial, HoverMaterial = srcHoverMaterial
            };


            PuncturedDiscGenerator discgen = new PuncturedDiscGenerator()
            {
                StartAngleDeg = 180, EndAngleDeg = 270, OuterRadius = 1.5f, InnerRadius = 0.75f
            };

            discgen.Generate();
            SimpleMesh discmesh = discgen.MakeSimpleMesh();

            MeshTransforms.Rotate(discmesh, Vector3d.Zero, Quaternionf.AxisAngleD(Vector3f.AxisX, 90));
            rotateGO = AppendMeshGO("object_rotate", new fMesh(discmesh), srcMaterial, gizmo);
            rotateGO.SetLocalScale(WidgetScale);

            Widgets[rotateGO] = new AxisRotationWidget(2)
            {
                RootGameObject = rotateGO, StandardMaterial = srcMaterial, HoverMaterial = srcHoverMaterial
            };


            gizmo.Hide();
        }