private bool CircleWithRadiusOf10GeometryFilter (Rhino.DocObjects.RhinoObject rhObject, GeometryBase geometry,
   ComponentIndex componentIndex)
 {
   bool is_circle_with_radius_of10 = false;
   Circle circle;
   if (geometry is Curve && (geometry as Curve).TryGetCircle(out circle))
     is_circle_with_radius_of10 = circle.Radius <= 10.0 + m_tolerance && circle.Radius >= 10.0 - m_tolerance;
   return is_circle_with_radius_of10;
 }
 /// <summary>
 /// Is called when a non-const operation occurs.
 /// </summary>
 protected override void OnSwitchToNonConst()
 {
   m_shallow_parent = null;
   base.OnSwitchToNonConst();
 }
 /// <summary>
 /// Verifies some geometry is a rectangle
 /// </summary>
 public static bool IsRectangle(GeometryBase geometry)
 {
     var polyline_curve = geometry as PolylineCurve;
       return polyline_curve != null && IsRectangle(polyline_curve);
 }
Example #4
0
        private void MoveBlades(bool down, GeometryBase geo)
        {
            //Left Blade
            if (geo == _bladeLeft)
            {
                //Margin Down
                if (down && _bladeLeftPosition.Y - Settings.BladeSizeHalf.Y < -Settings.GameBoardHalfSizeY + Settings.BladeSize.X)
                {
                    _bladeLeftPosition.Y = -Settings.GameBoardHalfSizeY + Settings.BladeSizeHalf.X + Settings.BladeSizeHalf.Y;
                    _bladeTransformLetft = Transform.Translation(_bladeLeftPosition - _bladeLeftInitialPosition);
                    return;
                }
                //Margin Up
                if (!down && _bladeLeftPosition.Y + Settings.BladeSizeHalf.Y > Settings.GameBoardHalfSizeY - Settings.BladeSize.X)
                {
                    _bladeLeftPosition.Y = Settings.GameBoardHalfSizeY - Settings.BladeSizeHalf.X - Settings.BladeSizeHalf.Y;
                    _bladeTransformLetft = Transform.Translation(_bladeLeftPosition - _bladeLeftInitialPosition);
                    return;
                }


                var motion = (_frameRenderMilliseconds * Settings.SpeedBladePlayer);

                if (down)
                    _bladeLeftPosition.Y -= motion;
                else
                    _bladeLeftPosition.Y += motion;

                _bladeTransformLetft = Transform.Translation(_bladeLeftPosition - _bladeLeftInitialPosition);

            }
            //Right Blade
            else if (geo == _bladeRight)
            {
                //Margin Down
                if (down && _bladeRightPosition.Y - Settings.BladeSizeHalf.Y < -Settings.GameBoardHalfSizeY + Settings.BladeSize.X)
                {
                    _bladeRightPosition.Y = -Settings.GameBoardHalfSizeY + Settings.BladeSizeHalf.X + Settings.BladeSizeHalf.Y;
                    _bladeTransformRight = Transform.Translation(_bladeRightPosition - _bladeRightInitialPosition);
                    return;
                }
                //Margin Up
                if (!down && _bladeRightPosition.Y + Settings.BladeSizeHalf.Y > Settings.GameBoardHalfSizeY - Settings.BladeSize.X)
                {
                    _bladeRightPosition.Y = Settings.GameBoardHalfSizeY - Settings.BladeSizeHalf.X - Settings.BladeSizeHalf.Y;
                    _bladeTransformRight = Transform.Translation(_bladeRightPosition - _bladeRightInitialPosition);
                    return;
                }
                
                var motion = (_frameRenderMilliseconds * Settings.IALevel.SpeedBladeIA);
                if (down)
                    _bladeRightPosition.Y -= motion;
                else
                    _bladeRightPosition.Y += motion;

                _bladeTransformRight = Transform.Translation(_bladeRightPosition - _bladeRightInitialPosition);
            }

        }
 /// <summary>
 /// This procedure contains the user code. Input parameters are provided as regular arguments,
 /// Output parameters as ref arguments. You don't have to assign output parameters,
 /// they will have a default value.
 /// </summary>
 private void RunScript(GeometryBase obj, List<Color> color, string layer, bool bake)
 {
     try{
       var objAttr = new ObjectAttributes();
       if(color.Count() != 0){
     objAttr.ColorSource = ObjectColorSource.ColorFromObject;
     objAttr.ObjectColor = color[0];
       }
       if(layer != ""){
     objAttr.LayerIndex = GetLayerNumber(RhinoDocument, layer);
       }
       if(bake){
     RhinoDocument.Objects.Add(obj, objAttr);
       }
     }catch(Exception e){
       Print(e.ToString());
     }
 }
Example #6
0
        /// <summary>
        /// Computes the distance of a point to a given geometry. (Brep, Mesh or closed Surface)
        /// </summary>
        public static double DistanceTo(GeometryBase geometry, Point3d testPoint, int spaceType)
        {
            double distanceTo = 0;
            Point3d closestPoint;

            switch (spaceType)
            {
                // Brep design space
                case 1:
                    closestPoint = ((Brep)geometry).ClosestPoint(testPoint);
                    distanceTo = testPoint.DistanceTo(closestPoint);
                    break;
                // Mesh design space
                case 2:
                    closestPoint = ((Mesh)geometry).ClosestPoint(testPoint);
                    distanceTo = testPoint.DistanceTo(closestPoint);
                    break;
                // Solid surface design space (must be converted to brep)
                case 3:
                    closestPoint = ((Surface)geometry).ToBrep().ClosestPoint(testPoint);
                    distanceTo = testPoint.DistanceTo(closestPoint);
                    break;
            }

            return distanceTo;
        }
Example #7
0
		/// <summary>
		/// We create a DisplayMesh object for each render mesh object we find.  If we encounter an Mesh object,
		/// we create a DisplayMesh object from the Mesh. For any Brep objects, we create Displaymesh objects
		/// from the render mesh.  For any Extrusion objects, we create a DisplayMesh from the RenderMesh.  For
		/// InstanceReference objects, _____
		/// </summary>
		protected virtual void PrepareObject (GeometryBase pObject, ObjectAttributes attr)
		{		
			while (LayerBBoxes.Count < ModelFile.Layers.Count) {
				BoundingBox invalidBBox = BoundingBox.Empty;
				LayerBBoxes.Add (invalidBBox);
			}

			// Geometry sorting...
			// Meshes--------------------------------------------------------------------------------------------
			if (pObject.ObjectType == ObjectType.Mesh /*&& attr.Mode != ObjectMode.InstanceDefinitionObject*/) {
				if (!(pObject as Mesh).IsValid) {
					(pObject as Mesh).Compact ();
					(pObject as Mesh).Normals.ComputeNormals ();
				}

				// Check to see if any of the vertices are hidden...if they are, remove them from the list
				for (int i = 0; i < (pObject as Mesh).Vertices.Count; i++) {
					bool vertexIsHidden = (pObject as Mesh).Vertices.IsHidden (i);
					if (vertexIsHidden) {
						(pObject as Mesh).Vertices.Remove (i, true);
					}
				}

				// Some 3dm files have meshes with no normals and this messes up the shading code...
				if (((pObject as Mesh).Normals.Count == 0) &&
				    ((pObject as Mesh).Vertices.Count > 0) &&
				    ((pObject as Mesh).Faces.Count > 0)) {
					(pObject as Mesh).Normals.ComputeNormals ();
				} 	

				GeometryCount++;
		
				AddModelMesh ((pObject as Mesh), attr);
				// Breps -------------------------------------------------------------------------------------------
			} else if (pObject.ObjectType == ObjectType.Brep) {
				BRepCount++;
				List<Mesh> meshes = new List<Mesh> ();

				//Loop through each BrepFace in the BRep and GetMesh, adding it to meshes
				int count = 0;
				foreach (BrepFace face in (pObject as Brep).Faces) {
					var renderMesh = face.GetMesh (MeshType.Render);
					if (renderMesh != null) {
						meshes.Add (face.GetMesh (MeshType.Render));
						count++;
					}
				}

				if (count > 0)
					BRepWithMeshCount++;
				if (count == 1) {
					if ((meshes [0] != null) && (meshes [0].Vertices.Count > 0)) {
						GeometryCount++;

						AddModelMesh (meshes [0], attr);
					}
				} else if (count > 0) {
					Mesh meshCandidate = new Mesh ();

					// Sometimes it's possible to have lists of NULL ON_Meshes...Rhino
					// can put them there as placeholders for badly formed/meshed breps.
					// Therefore, we need to always make sure we're actually looking at
					// a mesh that contains something and/or is not NULL.
					for (int i = 0; i < count; i++) {
						// If we have a valid pointer, append the mesh to our accumulator mesh...
						if (meshes [i] != null) {
							meshCandidate.Append (meshes [i]);
						}
					}

					// See if the end result actually contains anything and add it to our model if it does...
					if (meshCandidate.Vertices.Count > 0) {
						GeometryCount++;
						AddModelMesh (meshCandidate, attr);
					}
				}
				// Extrusions --------------------------------------------------------------------------------------
			} else if (pObject.ObjectType == ObjectType.Extrusion) { 
				ExtrusionCount++;

				Rhino.Geometry.Mesh meshCandidate = (pObject as Extrusion).GetMesh (Rhino.Geometry.MeshType.Render);

				// See if the end result actually contains anything and add it to our model if it does...
				if (meshCandidate != null) {
					if (meshCandidate.Vertices.Count > 0) {
						GeometryCount++;

						AddModelMesh(meshCandidate, attr);
					}
				}
				// Instance References -----------------------------------------------------------------------------
			} else if (pObject.ObjectType == ObjectType.InstanceReference) {
				Rhino.Geometry.InstanceReferenceGeometry instanceRef = (InstanceReferenceGeometry)pObject;
				ModelInstanceRef iRef = new ModelInstanceRef(attr.ObjectId, instanceRef.ParentIdefId, instanceRef.Xform);

				if (iRef != null) {
					iRef.LayerIndex = attr.LayerIndex;
					GeometryCount++;

					AddModelObject (iRef, attr);
				}
			}

		}
 /// <summary>
 /// Gets closest points between this and another curves.
 /// </summary>
 /// <param name="otherCurve">The other curve.</param>
 /// <param name="pointOnThisCurve">The point on this curve. This out parameter is assigned during this call.</param>
 /// <param name="pointOnOtherCurve">The point on other curve. This out parameter is assigned during this call.</param>
 /// <returns>true on success; false on error.</returns>
 public bool ClosestPoints(Curve otherCurve, out Point3d pointOnThisCurve, out Point3d pointOnOtherCurve)
 {
   GeometryBase[] a = new GeometryBase[] { otherCurve };
   int which;
   return ClosestPoints(a, out pointOnThisCurve, out pointOnOtherCurve, out which, 0.0);
 }
Example #9
0
 /// <summary>
 /// Checks geometry to see if it can be selected.
 /// Override to provide fancy filtering.
 /// </summary>
 /// <param name="rhObject">parent object being considered.</param>
 /// <param name="geometry">geometry being considered.</param>
 /// <param name="componentIndex">
 /// if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex.
 /// </param>
 /// <returns>
 /// The default returns true unless you've set a custom geometry filter. If a custom
 /// filter has been set, that delegate is called
 /// </returns>
 public virtual bool CustomGeometryFilter( DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex )
 {
   if (m_filter != null)
     return m_filter(rhObject, geometry, componentIndex);
   return true;
 }
Example #10
0
    /// <summary>
    /// Initializes a box that contains a generic piece of geometry.
    /// This box will be aligned with an arbitrary plane.
    /// </summary>
    /// <param name="basePlane">Base plane for aligned bounding box.</param>
    /// <param name="geometry">Geometry to box.</param>
    public Box(Plane basePlane, GeometryBase geometry)
    {
      // David: this code is untested.
      m_dx = new Interval(+1, -1);
      m_dy = new Interval(0, 0);
      m_dz = new Interval(0, 0);

      m_plane = basePlane;
      if (!m_plane.IsValid) { return; }

      Transform mapping = Geometry.Transform.ChangeBasis(Plane.WorldXY, m_plane);
      BoundingBox bbox = geometry.GetBoundingBox(mapping);

      m_dx = new Interval(bbox.Min.m_x, bbox.Max.m_x);
      m_dy = new Interval(bbox.Min.m_y, bbox.Max.m_y);
      m_dz = new Interval(bbox.Min.m_z, bbox.Max.m_z);

      MakeValid();
    }
Example #11
0
        /// <summary>
        /// Maps cell topology to the node grid and trims to the design space.
        /// </summary>
        public void UniformMapping(UnitCell cell, GeometryBase designSpace, int spaceType, float[] N, double minStrutLength, double maxStrutLength)
        {
            double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            for (int u = 0; u <= N[0]; u++)
            {
                for (int v = 0; v <= N[1]; v++)
                {
                    for (int w = 0; w <= N[2]; w++)
                    {
                        // We're inside a unit cell
                        // Loop through all pairs of nodes that make up struts
                        foreach (IndexPair nodePair in cell.NodePairs)
                        {
                            // Prepare the path of the nodes (path in tree)
                            // First, get relative paths of nodes (with respect to current unit cell)
                            int[] IRel = cell.NodePaths[nodePair.I];
                            int[] JRel = cell.NodePaths[nodePair.J];
                            // Next, compute absolute paths
                            GH_Path IPath = new GH_Path(u + IRel[0], v + IRel[1], w + IRel[2]);
                            GH_Path JPath = new GH_Path(u + JRel[0], v + JRel[1], w + JRel[2]);

                            // Make sure the cell exists
                            if (Nodes.PathExists(IPath) && Nodes.PathExists(JPath))
                            {
                                LatticeNode node1 = Nodes[IPath, IRel[3]];
                                LatticeNode node2 = Nodes[JPath, JRel[3]];
                                // Make sure both nodes exist:
                                // Null nodes either belong to other cells, or are beyond the upper uvw boundary
                                if (node1 != null && node2 != null)
                                {
                                    Curve fullCurve = new LineCurve(node1.Point3d, node2.Point3d);

                                    // If both nodes are inside, add full strut
                                    if (node1.IsInside && node2.IsInside)
                                    {
                                        Struts.Add(fullCurve);
                                    }
                                    // If neither node is inside, skip to next loop
                                    else if (!node1.IsInside && !node2.IsInside)
                                    {
                                        continue;
                                    }
                                    // Else, strut requires trimming
                                    else
                                    {
                                        // We are going to find the intersection point with the design space
                                        Point3d[] intersectionPts = null;
                                        Curve[] overlapCurves = null;
                                        LineCurve strutToTrim = null;

                                        switch (spaceType)
                                        {
                                            // Brep design space
                                            case 1:
                                                strutToTrim = new LineCurve(node1.Point3d, node2.Point3d);
                                                // Find intersection point
                                                Intersection.CurveBrep(strutToTrim, (Brep)designSpace, tol, out overlapCurves, out intersectionPts);
                                                break;
                                            // Mesh design space
                                            case 2:
                                                // Dummy faceIds variable for MeshLine call
                                                int[] faceIds;
                                                strutToTrim = new LineCurve(node1.Point3d, node2.Point3d);
                                                // Find intersection point
                                                intersectionPts = Intersection.MeshLine((Mesh)designSpace, strutToTrim.Line, out faceIds);
                                                break;
                                            // Solid surface design space
                                            case 3:
                                                // Dummy overlapCurves variable for CurveBrep call
                                                overlapCurves = null;
                                                strutToTrim = new LineCurve(node1.Point3d, node2.Point3d);
                                                // Find intersection point
                                                Intersection.CurveBrep(strutToTrim, ((Surface)designSpace).ToBrep(), tol, out overlapCurves, out intersectionPts);
                                                break;
                                        }

                                        LineCurve testLine = null;
                                        // Now, if an intersection point was found, trim the strut
                                        if (intersectionPts.Length > 0)
                                        {
                                            testLine = AddTrimmedStrut(node1, node2, intersectionPts[0], minStrutLength, maxStrutLength);
                                            // If the strut was succesfully trimmed, add it to the list
                                            if (testLine != null)
                                            {
                                                Struts.Add(testLine);
                                            }
                                        }
                                        else if (overlapCurves != null && overlapCurves.Length > 0)
                                        {
                                            Struts.Add(overlapCurves[0]);
                                        }

                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #12
0
    /// <summary>
    /// Moves changes made to this RhinoObject into the RhinoDoc.
    /// </summary>
    /// <returns>
    /// true if changes were made.
    /// </returns>
    /// <example>
    /// <code source='examples\vbnet\ex_addlayout.vb' lang='vbnet'/>
    /// <code source='examples\cs\ex_addlayout.cs' lang='cs'/>
    /// <code source='examples\py\ex_addlayout.py' lang='py'/>
    /// </example>
    public bool CommitChanges()
    {
      bool rc = false;

      if (null != m_edited_geometry)
      {
        CommitGeometryChangesFunc func = GetCommitFunc();
        if (null == func)
          return false;
        IntPtr pConstGeometry = m_edited_geometry.ConstPointer();
        uint serial_number = func(m_rhinoobject_serial_number, pConstGeometry);
        if (serial_number > 0)
        {
          rc = true;
          m_rhinoobject_serial_number = serial_number;
          m_edited_geometry = null;
        }
        else
          return false;
      }

      if (null != m_edited_attributes)
      {
        rc = Document.Objects.ModifyAttributes(this, m_edited_attributes, false);
        if (rc)
          m_edited_attributes = null;
      }

      return rc;
    }
Example #13
0
		/// <summary>
		/// Unions the entire ObjectTable BBox with the geo BBox and, if layerIndex is less than the count of layerBBox, 
		/// unions the LayerBBoxes list at the layerIndex provided with the geo BBox.
		/// </summary>
		protected virtual void AddObjectBoundingBox (GeometryBase geo, int layerIndex) 
		{
			ModelFile.Objects.GetBoundingBox().Union (geo.GetBoundingBox (false));

			if ((layerIndex >= 0) && (layerIndex < LayerBBoxes.Count ()))
				LayerBBoxes [layerIndex].Union (geo.GetBoundingBox (false));	                                          
		}
 /// <summary>
 /// Checks geometry to see if it can be selected.
 /// Override to provide fancy filtering.
 /// </summary>
 /// <param name="rhObject">parent object being considered.</param>
 /// <param name="geometry">geometry being considered.</param>
 /// <param name="componentIndex">
 /// if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex.
 /// </param>
 /// <returns>The default always returns true.</returns>
 public virtual bool CustomGeometryFilter( DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex )
 {
   return true;
 }
Example #15
0
        /// <summary>
        /// Validates a GeometryBase design space as a brep or a mesh.
        /// </summary>
        public static int ValidateSpace(ref GeometryBase designSpace)
        {
            // Types: 0-invalid, 1-brep, 2-mesh, 3-solid surface
            int type = 0;

            if (designSpace.ObjectType == ObjectType.Brep)
            {
                type = 1;
            }
            else if (designSpace.ObjectType == ObjectType.Mesh && ((Mesh)designSpace).IsClosed)
            {
                type = 2;
            }
            else if (designSpace.ObjectType == ObjectType.Surface && ((Surface)designSpace).IsSolid)
            {
                type = 3;
            }

            return type;
        }
 /// <summary>
 /// Checks geometry to see if it passes the basic GeometryAttributeFilter.
 /// </summary>
 /// <param name="rhObject">parent object being considered.</param>
 /// <param name="geometry">geometry being considered.</param>
 /// <param name="componentIndex">if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex.</param>
 /// <returns>
 /// true if the geometry passes the filter returned by GeometryAttributeFilter().
 /// </returns>
 public bool PassesGeometryAttributeFilter(DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex)
 {
   IntPtr pRhinoObject = IntPtr.Zero;
   if (rhObject != null)
     pRhinoObject = rhObject.ConstPointer();
   IntPtr pGeometry = IntPtr.Zero;
   if (geometry != null)
     pGeometry = geometry.ConstPointer();
   IntPtr ptr = NonConstPointer();
   return UnsafeNativeMethods.CRhinoGetObject_PassesGeometryAttributeFilter(ptr, pRhinoObject, pGeometry, componentIndex);
 }
Example #17
0
        /// <summary>
        /// Determines if a point is inside a geometry. (Brep, Mesh or closed Surface)
        /// </summary>
        public static bool IsPointInside(GeometryBase geometry, Point3d testPoint, int spaceType, double tol, bool strictlyIn)
        {
            bool isInside = false;

            switch (spaceType)
            {
                // Brep design space
                case 1:
                    isInside = ((Brep)geometry).IsPointInside(testPoint, tol, strictlyIn);
                    break;
                // Mesh design space
                case 2:
                    isInside = ((Mesh)geometry).IsPointInside(testPoint, tol, strictlyIn);
                    break;
                // Solid surface design space (must be converted to brep)
                case 3:
                    isInside = ((Surface)geometry).ToBrep().IsPointInside(testPoint, tol, strictlyIn);
                    break;
            }

            return isInside;
        }
Example #18
0
 /// <summary>
 /// Copies the unmanaged array to a managed counterpart.
 /// </summary>
 /// <returns>The managed array.</returns>
 public GeometryBase[] ToNonConstArray()
 {
   int count = UnsafeNativeMethods.ON_GeometryArray_Count(m_ptr);
   GeometryBase[] rc = new GeometryBase[count];
   for (int i = 0; i < count; i++)
   {
     IntPtr pGeometry = UnsafeNativeMethods.ON_GeometryArray_Get(m_ptr, i);
     rc[i] = GeometryBase.CreateGeometryHelper(pGeometry, null);
   }
   return rc;
 }
 /// <summary>
 /// Override to provide fancy object filtering
 /// </summary>
 public override bool CustomGeometryFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex)
 {
     return SampleCsRectangleHelper.IsRectangle(geometry);
 }