예제 #1
0
        public void AddInstance(Rhino.Geometry.Transform transform)
        {
            foreach (GltfMeshMaterialPair pair in  meshMaterialPairs)
            {
                Rhino.Geometry.Mesh rhinoMesh = pair.RhinoMesh.DuplicateMesh();

                rhinoMesh.Transform(GltfUtils.YupToZup * transform);

                rhinoMesh.TextureCoordinates.ReverseTextureCoordinates(1);

                Guid objectId = doc.Objects.AddMesh(rhinoMesh);

                Rhino.DocObjects.RhinoObject rhinoObject = doc.Objects.Find(objectId);

                Rhino.Render.RenderMaterial material = converter.GetMaterial(pair.MaterialIndex);

                if (rhinoObject != null && material != null)
                {
                    rhinoObject.RenderMaterial            = material;
                    rhinoObject.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                    rhinoObject.Attributes.Name           = pair.Name;

                    rhinoObject.CommitChanges();
                }
            }
        }
예제 #2
0
        public Rhino.Geometry.Transform GetMatrixTransform(glTFLoader.Schema.Node node)
        {
            Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Identity;

            if (node.Matrix != null)
            {
                xform.M00 = node.Matrix[0];
                xform.M01 = node.Matrix[1];
                xform.M02 = node.Matrix[2];
                xform.M03 = node.Matrix[3];
                xform.M10 = node.Matrix[4];
                xform.M11 = node.Matrix[5];
                xform.M12 = node.Matrix[6];
                xform.M13 = node.Matrix[7];
                xform.M20 = node.Matrix[8];
                xform.M21 = node.Matrix[9];
                xform.M22 = node.Matrix[10];
                xform.M23 = node.Matrix[11];
                xform.M30 = node.Matrix[12];
                xform.M31 = node.Matrix[13];
                xform.M32 = node.Matrix[14];
                xform.M33 = node.Matrix[15];

                xform = xform.Transpose();
            }

            return(xform);
        }
예제 #3
0
        private void GetLights()
        {
            LightTable        allLights = doc.Lights;
            List <UnifyLight> lightList = new List <UnifyLight>();

            foreach (LightObject light in allLights)
            {
                UnifyLight unifyObj = new UnifyLight();

                unifyObj.ObjType    = "LightObject";
                unifyObj.LightType  = light.LightGeometry.LightStyle.ToString();
                unifyObj.Guid       = light.Id;
                unifyObj.Diffuse    = Utility.ColorToString(light.LightGeometry.Diffuse);
                unifyObj.UniqueName = light.LightGeometry.LightStyle.ToString() + "-" + light.Id.ToString();
                unifyObj.Intensity  = light.LightGeometry.Intensity;

                if (light.LightGeometry.LightStyle == Rhino.Geometry.LightStyle.WorldRectangular)
                {
                    // adjust location, rhino reports location at lower left corner
                    // unity reports location at center of the area/rectangle
                    Rhino.Geometry.Point3d loc = new Rhino.Geometry.Point3d(
                        light.LightGeometry.Location.X + (light.LightGeometry.Length.Length * 0.5),
                        light.LightGeometry.Location.Y + (light.LightGeometry.Width.Length * 0.5),
                        light.LightGeometry.Location.Z);
                    unifyObj.Location = loc.ToString();

                    // create target from location + direction
                    Rhino.Geometry.Transform xf     = Rhino.Geometry.Transform.Translation(light.LightGeometry.Direction);
                    Rhino.Geometry.Point3d   target = loc;
                    loc.Transform(xf);
                    unifyObj.Target = target.ToString();
                }
                else
                {
                    // create target from location + direction
                    Rhino.Geometry.Transform xf     = Rhino.Geometry.Transform.Translation(light.LightGeometry.Direction);
                    Rhino.Geometry.Point3d   target = light.LightGeometry.Location;
                    target.Transform(xf);
                    unifyObj.Target = target.ToString();

                    unifyObj.Location = light.LightGeometry.Location.ToString();
                }

                unifyObj.Range           = light.LightGeometry.Direction.Length;
                unifyObj.SpotAngle       = light.LightGeometry.SpotAngleRadians;
                unifyObj.ShadowIntensity = light.LightGeometry.SpotLightShadowIntensity;
                unifyObj.Width           = light.LightGeometry.Width.Length;
                unifyObj.Length          = light.LightGeometry.Length.Length;

                if (light.IsDeleted)
                {
                    unifyObj.Deleted = true;
                }

                lightList.Add(unifyObj);
            }

            this.Lights = lightList;
        }
예제 #4
0
 /// <summary>
 /// Rotates a viewport about an axis relative to a center point
 /// </summary>
 public static void RotateView(this ViewportInfo viewport, Rhino.Geometry.Vector3d axis, Rhino.Geometry.Point3d center, double angle)
 {
     Rhino.Geometry.Point3d   cameraLocation = viewport.CameraLocation;
     Rhino.Geometry.Vector3d  cameraY        = viewport.CameraY;
     Rhino.Geometry.Vector3d  cameraZ        = viewport.CameraZ;
     Rhino.Geometry.Transform rotation       = Rhino.Geometry.Transform.Rotation(angle, axis, center);
     cameraLocation = rotation * cameraLocation;
     cameraY        = rotation * cameraY;
     cameraZ        = -(rotation * cameraZ);
     viewport.SetCameraLocation(cameraLocation);
     viewport.SetCameraDirection(cameraZ);
     viewport.SetCameraUp(cameraY);
 }
예제 #5
0
        Rhino.Geometry.Transform GetNodeTransform(glTFLoader.Schema.Node node)
        {
            Rhino.Geometry.Transform matrixTransform = GetMatrixTransform(node);

            if (!matrixTransform.IsIdentity)
            {
                return(matrixTransform);
            }
            else
            {
                return(GetTrsTransform(node));
            }
        }
예제 #6
0
        /// <summary>
        /// Sets the viewport's camera location, target and up vector
        /// </summary>
        public static void SetTarget(this ViewportInfo viewport, Rhino.Geometry.Point3d targetLocation, Rhino.Geometry.Point3d cameraLocation, Rhino.Geometry.Vector3d cameraUp)
        {
            Rhino.Geometry.Vector3d cameraDirection = targetLocation - cameraLocation;
            cameraDirection.Unitize();

            if (!viewport.CameraDirection.IsTiny())
            {
                Rhino.Geometry.Vector3d cameraDirection0 = -viewport.CameraZ;
                Rhino.Geometry.Vector3d cameraY          = viewport.CameraY;
                const double            tiltAngle        = 0;

                viewport.SetCameraLocation(cameraLocation);
                viewport.SetCameraDirection(cameraDirection);

                bool didSetTarget = false;
                didSetTarget = viewport.SetCameraUp(cameraUp);

                if (!didSetTarget)
                {
                    didSetTarget = viewport.SetCameraUp(cameraY);
                    cameraUp     = cameraY;
                }

                if (!didSetTarget)
                {
                    Rhino.Geometry.Vector3d rotationAxis = Rhino.Geometry.Vector3d.CrossProduct(cameraDirection0, cameraDirection);
                    double sinAngle = rotationAxis.Length;
                    double cosAngle = cameraDirection0 * cameraDirection;
                    Rhino.Geometry.Transform rot = Rhino.Geometry.Transform.Rotation(sinAngle, cosAngle, rotationAxis, Rhino.Geometry.Point3d.Origin);
                    cameraUp     = rot * cameraY;
                    didSetTarget = viewport.SetCameraUp(cameraUp);
                }

                if (didSetTarget)
                {
                    // Apply tilt angle to new camera and target location
                    if (Math.Abs(tiltAngle) > 1.0e-6)
                    {
                        Rhino.Geometry.Transform rot = Rhino.Geometry.Transform.Rotation(tiltAngle, -cameraDirection0, cameraLocation);
                        cameraUp     = rot * cameraUp;
                        didSetTarget = viewport.SetCameraUp(cameraUp);
                    }

                    if (didSetTarget)
                    {
                        viewport.TargetPoint = targetLocation;
                    }
                }
            }
        }
예제 #7
0
        private static void OnTransformUserData(int serial_number, ref Rhino.Geometry.Transform xform)
        {
            UserData ud = FromSerialNumber(serial_number);

            if (ud != null)
            {
                try
                {
                    ud.OnTransform(xform);
                }
                catch (Exception ex)
                {
                    Runtime.HostUtils.ExceptionReport(ex);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Rotates the viewport around an axis by an angle
        /// </summary>
        public static void RotateCameraAround(this ViewportInfo viewport, Rhino.Geometry.Vector3d axis, double angle)
        {
            Rhino.Geometry.Point3d cameraLocation = viewport.CameraLocation;
            double targetDistance = (cameraLocation - viewport.TargetPoint) * viewport.CameraZ;

            Rhino.Geometry.Transform rotationTransform = Rhino.Geometry.Transform.Rotation(angle, axis, cameraLocation);
            Rhino.Geometry.Vector3d  cameraDirection   = -(rotationTransform * viewport.CameraZ);
            if (cameraDirection.Z >= -0.99 && cameraDirection.Z <= 0.99)                        // avoid gimbal "lock"
            {
                Rhino.Geometry.Point3d target = cameraLocation + targetDistance * cameraDirection;
                viewport.TargetPoint = target;
                viewport.SetCameraLocation(cameraLocation);
                viewport.SetCameraDirection(cameraDirection);
                viewport.SetCameraUp(Rhino.Geometry.Vector3d.ZAxis);
            }
        }
예제 #9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Define a unit Brep box
            Rhino.Geometry.Point3d     min  = new Rhino.Geometry.Point3d(0.0, 0.0, 0.0);
            Rhino.Geometry.Point3d     max  = new Rhino.Geometry.Point3d(1.0, 1.0, 1.0);
            Rhino.Geometry.BoundingBox bbox = new Rhino.Geometry.BoundingBox(min, max);
            Rhino.Geometry.Brep        brep = Rhino.Geometry.Brep.CreateFromBox(bbox);

            // Add a copy to the document
            doc.Objects.AddBrep(brep);

            // Create and define the arguments of the array
            SampleCsArrayArgs args = new SampleCsArrayArgs();

            args.CountX    = 10;
            args.CountY    = 10;
            args.CountZ    = 10;
            args.DistanceX = 1.0;
            args.DistanceY = 1.0;
            args.DistanceZ = 1.0;
            // Calculate the offsets
            args.CalculateOffsets();

            // Array the unit Brep box
            for (int i = 0; i < args.Offsets.Count; i++)
            {
                // Skip the first one...
                if (!args.Offsets[i].IsZero)
                {
                    Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(args.Offsets[i]);
                    if (xform.IsValid && xform != Rhino.Geometry.Transform.Identity)
                    {
                        Rhino.Geometry.Brep dupBrep = brep.DuplicateBrep();
                        dupBrep.Transform(xform);
                        if (dupBrep.IsValid)
                        {
                            doc.Objects.AddBrep(dupBrep);
                        }
                    }
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
예제 #10
0
        /// <summary>
        /// Constructs a Rhino_DotNet OnXform from a given RhinoCommon Transform.
        /// </summary>
        /// <param name="source">A RhinoCommon source transform.</param>
        /// <returns>
        /// Rhino_DotNet object on success. This will be an independent copy.
        /// </returns>
        public static object ToOnXform(Rhino.Geometry.Transform source)
        {
            object rc     = null;
            Type   onType = GetRhinoDotNetType("RMA.OpenNURBS.OnXform");

            if (null != onType)
            {
                double[] vals = new double[16];
                for (int row = 0; row < 4; row++)
                {
                    for (int column = 0; column < 4; column++)
                    {
                        vals[4 * row + column] = source[row, column];
                    }
                }
                rc = System.Activator.CreateInstance(onType, new object[] { vals });
            }
            return(rc);
        }
예제 #11
0
        private void AddNodeRecursive(glTFLoader.Schema.Node node, Rhino.Geometry.Transform transform)
        {
            Rhino.Geometry.Transform finalTransform = transform * GetNodeTransform(node);

            if (node.Mesh.HasValue)
            {
                meshHolders[node.Mesh.Value].AddInstance(finalTransform);
            }

            if (node.Children != null)
            {
                foreach (int childIndex in node.Children)
                {
                    glTFLoader.Schema.Node child = gltf.Nodes[childIndex];

                    AddNodeRecursive(child, finalTransform);
                }
            }
        }
예제 #12
0
        private void ExplodeRecursive(InstanceObject instanceObject, Rhino.Geometry.Transform instanceTransform, List <RhinoObject> pieces, List <Rhino.Geometry.Transform> transforms)
        {
            for (int i = 0; i < instanceObject.InstanceDefinition.ObjectCount; i++)
            {
                RhinoObject rhinoObject = instanceObject.InstanceDefinition.Object(i);

                if (rhinoObject is InstanceObject nestedObject)
                {
                    Rhino.Geometry.Transform nestedTransform = instanceTransform * nestedObject.InstanceXform;

                    ExplodeRecursive(nestedObject, nestedTransform, pieces, transforms);
                }
                else
                {
                    pieces.Add(rhinoObject);

                    transforms.Add(instanceTransform);
                }
            }
        }
예제 #13
0
        public Rhino.Geometry.Transform GetTrsTransform(glTFLoader.Schema.Node node)
        {
            Rhino.Geometry.Vector3d translation = Rhino.Geometry.Vector3d.Zero;

            if (node.Translation != null && node.Translation.Length == 3)
            {
                translation.X = node.Translation[0];
                translation.Y = node.Translation[1];
                translation.Z = node.Translation[2];
            }

            Rhino.Geometry.Quaternion rotation = Rhino.Geometry.Quaternion.Identity;

            if (node.Rotation != null && node.Rotation.Length == 4)
            {
                rotation.A = node.Rotation[3];
                rotation.B = node.Rotation[0];
                rotation.C = node.Rotation[1];
                rotation.D = node.Rotation[2];
            }

            Rhino.Geometry.Vector3d scaling = Rhino.Geometry.Vector3d.Zero;

            if (node.Scale != null && node.Scale.Length == 3)
            {
                scaling.X = node.Scale[0];
                scaling.Y = node.Scale[1];
                scaling.Z = node.Scale[2];
            }

            Rhino.Geometry.Transform translationTransform = Rhino.Geometry.Transform.Translation(translation);

            rotation.GetRotation(out double angle, out Rhino.Geometry.Vector3d axis);

            Rhino.Geometry.Transform rotationTransform = Rhino.Geometry.Transform.Rotation(angle, axis, Rhino.Geometry.Point3d.Origin);

            Rhino.Geometry.Transform scalingTransform = Rhino.Geometry.Transform.Scale(Rhino.Geometry.Plane.WorldXY, scaling.X, scaling.Y, scaling.Z);

            return(translationTransform * rotationTransform * scalingTransform);
        }
예제 #14
0
        /// <summary>
        /// LateralPan of a viewport between two points
        /// </summary>
        public static void LateralPan(this ViewportInfo viewport, CGPoint fromPoint, CGPoint toPoint, bool flipX, bool flipY)
        {
            double deltaX, deltaY, s;

            Rhino.Geometry.Transform s2c          = viewport.GetXform(CoordinateSystem.Screen, CoordinateSystem.Clip);
            Rhino.Geometry.Point3d   screenPoint0 = new Rhino.Geometry.Point3d(fromPoint.X, fromPoint.Y, 0.0);
            Rhino.Geometry.Point3d   screenPoint1 = new Rhino.Geometry.Point3d(toPoint.X, toPoint.Y, 0.0);
            Rhino.Geometry.Point3d   clipPoint0   = s2c * screenPoint0;
            Rhino.Geometry.Point3d   clipPoint1   = s2c * screenPoint1;
            deltaX  = 0.5 * (clipPoint1.X - clipPoint0.X);
            deltaY  = 0.5 * (clipPoint1.Y - clipPoint0.Y);
            deltaX *= (viewport.FrustumRight - viewport.FrustumLeft);
            deltaY *= (viewport.FrustumBottom - viewport.FrustumTop);
            if (viewport.IsPerspectiveProjection)
            {
                s       = viewport.TargetPoint.DistanceTo(viewport.CameraLocation) / viewport.FrustumNear;
                deltaX *= flipX ? -s : s;
                deltaY *= flipY ? -s : s;
            }
            Rhino.Geometry.Vector3d dollyVector = (deltaX * viewport.CameraX) + (deltaY * viewport.CameraY);
            viewport.TargetPoint = viewport.TargetPoint - dollyVector;
            viewport.SetCameraLocation(viewport.CameraLocation - dollyVector);
        }
 /// <summary>
 /// Called for each frame. Starting at 0.0.
 /// </summary>
 /// <param name="doc">doc is the current document.</param>
 /// <param name="doc_object">doc_obj is the current object.</param>
 /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot.
 /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param>
 /// <param name="dPos">dPos is the current frame. Starting at 0.0.</param>
 /// <param name="archive_start">archive_start is a archive to the data of the starting position.</param>
 /// <param name="archive_stop">archive_stop is a archive to the data of the ending position.</param>
 /// <returns></returns>
 /// <since>6.0</since>
 public abstract bool AnimateObject(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, double dPos, BinaryArchiveReader archive_start, BinaryArchiveReader archive_stop);
 /// <summary>
 /// Called once at the start of an animation. This can be used to extend the scene bounding box to avoid clipping.
 /// </summary>
 /// <param name="doc">doc is the current document.</param>
 /// <param name="doc_object">doc_obj is the current object.</param>
 /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot.
 /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param>
 /// <param name="archive_start">archive_start is a archive to the data of the starting position.</param>
 /// <param name="archive_stop">archive_stop is a archive to the data of the ending position.</param>
 /// <param name="bbox">bbox is the current scene bounding box.</param>
 /// <since>6.0</since>
 public abstract void ExtendBoundingBoxForObjectAnimation(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, BinaryArchiveReader archive_start, BinaryArchiveReader archive_stop, ref Rhino.Geometry.BoundingBox bbox);
 /// <summary>
 /// Called once at the start of an animation.
 /// </summary>
 /// <param name="doc">doc is the current document.</param>
 /// <param name="doc_object">doc_obj is the current object.</param>
 /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot.
 /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param>
 /// <param name="archive_start">archive_start is a archive to the data of the starting position.</param>
 /// <param name="archive_stop">archive_stop is a archive to the data of the ending position.</param>
 /// <returns>true if successful, otherwise false.</returns>
 /// <since>6.0</since>
 public abstract bool PrepareForObjectAnimation(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, BinaryArchiveReader archive_start, BinaryArchiveReader archive_stop);
 /// <summary>
 /// Called when the user restores a snapshot and SupportsObjects() and SupportsObject(Rhino.DocObjects.RhinoObject doc_object) returns true.
 /// </summary>
 /// <param name="doc">doc is the current document.</param>
 /// <param name="doc_object">doc_obj is the current object.</param>
 /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot.
 /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param>
 /// <param name="archive">archive is the archive to read the data from.</param>
 /// <returns>true if successful, otherwise false.</returns>
 /// <since>6.0</since>
 public abstract bool RestoreObject(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, BinaryArchiveReader archive);
예제 #19
0
 public TransformField(string internalName, string friendlyName, Rhino.Geometry.Transform defaultValue)
   : base(internalName, friendlyName)
 {
   m_defaultValue = defaultValue;
 }
예제 #20
0
    internal static IntPtr ReadIntoProfileContext(System.Runtime.Serialization.SerializationInfo info, string sectionBase)
    {
      IntPtr pProfileContext = UnsafeNativeMethods.CRhCmnProfileContext_New();
      var e = info.GetEnumerator();
      while (e.MoveNext())
      {
        string entry = e.Name.Replace("::", "\\");
        string section = sectionBase;
        int split_index = entry.LastIndexOf("\\", System.StringComparison.Ordinal);
        if (split_index > -1)
        {
          section = sectionBase + "\\" + entry.Substring(0, split_index);
          entry = entry.Substring(split_index + 1);
        }

        
        Type t = e.ObjectType;
        if( typeof(string) == t )
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileString(pProfileContext, section, entry, e.Value as string);
        else if( typeof(Guid) == t )
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileUuid(pProfileContext, section, entry, (Guid)e.Value);
        else if( typeof(System.Drawing.Color) == t )
        {
          System.Drawing.Color c = (System.Drawing.Color)e.Value;
          int argb = c.ToArgb();
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileColor(pProfileContext, section, entry, argb);
        }
        else if( typeof(int) == t )
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileInt(pProfileContext, section, entry, (int)e.Value);
        else if( typeof(double) == t )
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileDouble(pProfileContext, section, entry, (double)e.Value);
        else if( typeof(System.Drawing.Rectangle) == t )
        {
          System.Drawing.Rectangle r = (System.Drawing.Rectangle)e.Value;
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileRect(pProfileContext, section, entry, r.Left, r.Top, r.Right, r.Bottom);
        }
        else if( typeof(System.Drawing.Point) == t )
        {
          System.Drawing.Point pt = (System.Drawing.Point)e.Value;
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfilePoint(pProfileContext, section, entry, pt.X, pt.Y);
        }
        else if( typeof(Rhino.Geometry.Point3d) == t )
        {
          Rhino.Geometry.Point3d pt = (Rhino.Geometry.Point3d)e.Value;
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfilePoint3d(pProfileContext, section, entry, pt);
        }
        else if( typeof(Rhino.Geometry.Transform) == t )
        {
          Rhino.Geometry.Transform xf = (Rhino.Geometry.Transform)e.Value;
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileXform(pProfileContext, section, entry, ref xf);
        }
        else if( typeof(Rhino.Geometry.Vector3d) == t )
        {
          Rhino.Geometry.Vector3d v = (Rhino.Geometry.Vector3d)e.Value;
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileVector3d(pProfileContext, section, entry, v);
        }
        else if( typeof(Rhino.Geometry.MeshingParameters) == t )
        {
          Rhino.Geometry.MeshingParameters mp = e.Value as Rhino.Geometry.MeshingParameters;
          if (mp != null)
          {
            IntPtr pMp = mp.ConstPointer();
            UnsafeNativeMethods.CRhinoProfileContext_SaveProfileMeshingParameters(pProfileContext, section, entry, pMp);
          }
        }
        else if( typeof(byte[]) == t )
        {
          byte[] b = e.Value as byte[];
          if (b != null)
          {
            UnsafeNativeMethods.CRhinoProfileContext_SaveProfileBuffer(pProfileContext, section, entry, b.Length, b);
          }
        }
        else if (typeof(bool) == t)
          UnsafeNativeMethods.CRhinoProfileContext_SaveProfileBool(pProfileContext, section, entry, (bool)e.Value);
        else
        {
          //try
          //{
            string s = info.GetString(e.Name);
            UnsafeNativeMethods.CRhinoProfileContext_SaveProfileString(pProfileContext, section, entry, s);
          //}
          //catch (Exception ex)
          //{
          //  throw;
          //}
        }
      }
      return pProfileContext;
    }
 public Rhino.Geometry.Transform GetInstanceTransform(int index)
 {
     Rhino.Geometry.Transform xform = new Rhino.Geometry.Transform();
     UnsafeNativeMethods.Rdk_CustomMeshes_GetInstanceTransform(ConstPointer(), index, ref xform);
     return(xform);
 }
예제 #22
0
 public Rhino.Geometry.Transform ToTransform()
 {
     Rhino.Geometry.Transform v = new Rhino.Geometry.Transform();
     UnsafeNativeMethods.Rdk_Variant_GetXformValue(ConstPointer(), ref v);
     return(v);
 }
예제 #23
0
 public override void BakeGeometry(Rhino.RhinoDoc doc, Rhino.DocObjects.ObjectAttributes att, List <Guid> obj_ids)
 {
     Rhino.Geometry.Transform          zDown_airy = Rhino.Geometry.Transform.Translation(0, 0, 2d);
     Rhino.DocObjects.ObjectAttributes a2         = att.Duplicate();
     a2.LayerIndex = 2;
     Rhino.DocObjects.ObjectAttributes a3 = att.Duplicate();
     a3.LayerIndex = 3;
     Rhino.DocObjects.ObjectAttributes a4 = att.Duplicate();
     a4.LayerIndex = 4;
     Rhino.DocObjects.ObjectAttributes a5 = att.Duplicate();
     a5.LayerIndex = 5;
     Rhino.DocObjects.ObjectAttributes a6 = att.Duplicate();
     a6.LayerIndex = 6;
     Rhino.DocObjects.ObjectAttributes a7 = att.Duplicate();
     a7.LayerIndex = 7;
     foreach (var leaf in listLeaf)
     {
         var airySrf = leaf.airySrf.Duplicate() as Rhino.Geometry.NurbsSurface;
         airySrf.Transform(zScale);
         airySrf.Transform(zDown_airy);
         Guid id = doc.Objects.AddSurface(airySrf, a2);
         obj_ids.Add(id);
         var srf = leaf.shellSrf.Duplicate() as Rhino.Geometry.NurbsSurface;
         srf.Transform(zDown_eq);
         id = doc.Objects.AddSurface(srf, a3);
         obj_ids.Add(id);
     }
     foreach (var branch in listBranch)
     {
         //var airyCrv=branch.airyCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
         //airyCrv.Transform(zDown_airy);
         //Guid id = doc.Objects.AddCurve(airyCrv, a2);
         //obj_ids.Add(id);
         if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce)
         {
             var crv = branch.shellCrv.Duplicate() as Rhino.Geometry.NurbsCurve;
             crv.Transform(zDown_eq);
             Guid id = doc.Objects.AddCurve(crv, a7);
             obj_ids.Add(id);
         }
     }
     if (crossMagenta != null)
     {
         foreach (var line in crossMagenta)
         {
             Guid id = doc.Objects.AddLine(line, a4);
             obj_ids.Add(id);
         }
     }
     if (listBranch != null)
     {
         foreach (var branch in listBranch)
         {
             if (branch.branchType == branch.type.fix)
             {
                 if (branch.tuples != null)
                 {
                     foreach (var tup in branch.tuples)
                     {
                         var circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), 0.5);
                         circle.Transform(zDown);
                         Guid id = doc.Objects.AddCircle(circle, a6);
                         obj_ids.Add(id);
                         circle = new Rhino.Geometry.Circle(new Rhino.Geometry.Point3d(tup.x, tup.y, branch.slice2.height), 0.5);
                         circle.Transform(zDown_eq);
                         id = doc.Objects.AddCircle(circle, a6);
                         obj_ids.Add(id);
                     }
                 }
             }
             if (branch.branchType == branch.type.kink || branch.branchType == branch.type.reinforce)
             {
                 if (branch.tuples != null)
                 {
                     foreach (var tup in branch.tuples)
                     {
                         var D = tup.SPK[0, 0] / 2d;
                         if (D > 0)
                         {
                             var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z), new Rhino.Geometry.Point3d(tup.x, tup.y, tup.z + D));
                             line.Transform(zDown);
                             Guid id = doc.Objects.AddLine(line, a5);
                             obj_ids.Add(id);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #24
0
 public Rhino.Geometry.Transform ToTransform()
 {
   Rhino.Geometry.Transform v = new Rhino.Geometry.Transform();
   UnsafeNativeMethods.Rdk_Variant_GetXformValue(ConstPointer(), ref v);
   return v;
 }
예제 #25
0
        /***************************************************/

        public virtual Rhino.Geometry.BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            Rhino.Geometry.BoundingBox box = Bounds();
            box.Transform(xform);
            return(box);
        }
 /// <summary>
 /// Called for every object that is associated with a snapshot and gets transformed in Rhino. This is getting called for each stored snapshot and gives the client the possibility to update the stored data.
 /// </summary>
 /// <param name="doc">doc is the current document.</param>
 /// <param name="doc_object">doc_obj is the current object.</param>
 /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot.
 /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param>
 /// <param name="archive">archive is a archive which can be used to update the stored data.</param>
 /// <returns>true if successful, otherwise false.</returns>
 /// <since>6.0</since>
 public abstract bool ObjectTransformNotification(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, BinaryArchiveReader archive);
예제 #27
0
 /// <summary>
 /// Computes a transform from a coordinate system to another.
 /// </summary>
 /// <param name="sourceSystem">The coordinate system to map from.</param>
 /// <param name="destinationSystem">The coordinate system to map into.</param>
 /// <returns>The 4x4 transformation matrix (acts on the left).</returns>
 public Rhino.Geometry.Transform GetXform(Rhino.DocObjects.CoordinateSystem sourceSystem, Rhino.DocObjects.CoordinateSystem destinationSystem)
 {
   Rhino.Geometry.Transform matrix = new Rhino.Geometry.Transform();
   IntPtr pConstThis = ConstPointer();
   if (!UnsafeNativeMethods.ON_Viewport_GetXform(pConstThis, (int)sourceSystem, (int)destinationSystem, ref matrix))
     matrix = Rhino.Geometry.Transform.Unset;
   return matrix;
 }
예제 #28
0
        public void SetPickTransform(Rhino.Geometry.Transform transform)
        {
            IntPtr pThis = NonConstPointer();

            UnsafeNativeMethods.CRhinoPickContext_SetPickTransform(pThis, ref transform);
        }
 public void SetInstanceTransform(int index, Rhino.Geometry.Transform xform)
 {
     UnsafeNativeMethods.Rdk_CustomMeshes_SetInstanceTransform(NonConstPointer(), index, xform);
 }
 /// <summary>
 /// Called when the user saves a snapshot and SupportsObjects() and SupportsObject(Rhino.DocObjects.RhinoObject doc_object) returns true.
 /// </summary>
 /// <param name="doc">doc is the current document.</param>
 /// <param name="doc_object">doc_obj is the current object.</param>
 /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot.
 /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param>
 /// <param name="archive">archive is the archive to write the data to.</param>
 /// <returns>true if successful, otherwise false.</returns>
 /// <since>6.0</since>
 public abstract bool SaveObject(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, BinaryArchiveWriter archive);
 public Rhino.Geometry.Transform GetInstanceTransform(int index)
 {
   Rhino.Geometry.Transform xform = new Rhino.Geometry.Transform();
   UnsafeNativeMethods.Rdk_CustomMeshes_GetInstanceTransform(ConstPointer(), index, ref xform);
   return xform;
 }
예제 #32
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            stw.Stop();
            string dbg = stw.ElapsedMilliseconds.ToString();

            stw.Reset();
            double dist = 0;

            if (!DA.GetData(1, ref dist))
            {
                return;
            }
            if (_go == false)
            {
                t = 0;
                FriedChiken.clear();
                lpS = new List <GH_particleSystem>();

                if (fixedPointsGuids != null)
                {
                    foreach (Guid[] gs in fixedPointsGuids)
                    {
                        foreach (Guid g in gs)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.Delete(g, true);
                        }
                    }
                    fixedPointsGuids = null;
                }

                if (!DA.GetDataList(0, lpS))
                {
                    return;
                }
                particleSystem[] _ps = null;
                _ps = new particleSystem[lpS.Count];
                for (int i = 0; i < lpS.Count; i++)
                {
                    _ps[i] = lpS[i].Value;
                }
                FriedChiken.addParticleSystems(_ps);
                //FriedChiken.begin();
                __dist = dist;
                lS     = new List <Rhino.Geometry.GeometryBase>();
                lPC    = new List <Rhino.Geometry.PointCloud>();

                lfN = new List <NumericalMethodHelper.objects.fixedNodes>();
                fixedPointsGuids = new List <Guid[]>();

                foreach (GH_particleSystem pS in lpS)
                {
                    if (pS != null)
                    {
                        if (pS.UPGR != null)
                        {
                            pS.UPGR(dist, 0, 0);
                        }
                    }
                }
            }
            else
            {
                double dt = full.getDt();
                if (t == 0)
                {
                    output = new List <string>();
                    //firstAction(DA);
                    FriedChiken.clear();
                    lpS = new List <GH_particleSystem>();
                    if (!DA.GetDataList(0, lpS))
                    {
                        return;
                    }
                    particleSystem[] _ps = null;
                    _ps = new particleSystem[lpS.Count];
                    for (int i = 0; i < lpS.Count; i++)
                    {
                        _ps[i] = lpS[i].Value;
                    }
                    FriedChiken.addParticleSystems(_ps);
                    if (fixedPointsGuids != null)
                    {
                        foreach (Guid[] gs in fixedPointsGuids)
                        {
                            foreach (Guid g in gs)
                            {
                                Rhino.RhinoDoc.ActiveDoc.Objects.Delete(g, true);
                            }
                        }
                    }
                    FriedChiken.begin();
                    refX   = DoubleArray.From(FriedChiken.x.rawData);
                    __dist = dist;
                    if (FriedChiken.numCond > 0)
                    {
                        lambda = new vector(FriedChiken.numCond).zeros();
                        dx     = new vector(FriedChiken.q.nElem);
                        qo     = new vector(FriedChiken.q.nElem);
                        qr     = new vector(FriedChiken.numCond).zeros();
                    }
                    lS  = new List <Rhino.Geometry.GeometryBase>();
                    lPC = new List <Rhino.Geometry.PointCloud>();

                    lfN = new List <NumericalMethodHelper.objects.fixedNodes>();
                    fixedPointsGuids = new List <Guid[]>();
                    for (int i = 0; i < FriedChiken.particleSystems.Count; i++)
                    {
                        for (int j = 0; j < FriedChiken.particleSystems[i].objList.Count; j++)
                        {
                            if (FriedChiken.particleSystems[i].objList[j] is mikity.NumericalMethodHelper.objects.fixedNodes)
                            {
                                mikity.NumericalMethodHelper.objects.fixedNodes fN = (mikity.NumericalMethodHelper.objects.fixedNodes)FriedChiken.particleSystems[i].objList[j];
                                lfN.Add(fN);
                                fixedPointsGuids.Add(new Guid[fN.nNodes]);
                                Rhino.Geometry.Point3d[] ps = new Rhino.Geometry.Point3d[fN.nNodes];
                                Guid[] gs = fixedPointsGuids[fixedPointsGuids.Count - 1];

                                for (int k = 0; k < fN.nNodes; k++)
                                {
                                    ps[k] = new Rhino.Geometry.Point3d(fN.nodeList[k].getNodes()[0, 0] + dist, fN.nodeList[k].getNodes()[0, 1], fN.nodeList[k].getNodes()[0, 2]);
                                    gs[k] = Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(ps[k]);
                                }
                                Rhino.RhinoDoc.ActiveDoc.Groups.Add(gs);
                            }
                        }
                    }
                }
                //Computation

                while (stw.ElapsedMilliseconds < 25)
                {
                    stw.Start();
                    FriedChiken.Tick(t); //要素アップデート、勾配の計算
                    FriedChiken.Tack(t); //マスク等後処理
                    if (_IF)
                    {
                        FriedChiken.omega.zeros();
                    }
                    double resid = 0;
                    if (FriedChiken.numCond > 0)
                    {
                        resid = FriedChiken.getResidual().norm;
                        phi();
                    }
                    string tmp = "\t" + t.ToString() + "\t";
                    tmp += FriedChiken.omega.norm.ToString() + "\t";

                    if (_geodesic)
                    {
                        if (FriedChiken.numCond > 0)
                        {
                            varphi();
                        }
                    }
                    var    v     = DoubleArray.From(FriedChiken.q.rawData);
                    double normW = FriedChiken.omega.norm;
                    if (_normalize == true)
                    {
                        if (normW != 0)
                        {
                            FriedChiken.omega.dividedby(normW);//力を正規化
                        }
                        normW = FriedChiken.omega.norm;
                    }
                    var a = DoubleArray.From(FriedChiken.omega.rawData);

                    FriedChiken.omega.MinusTo(FriedChiken.r);//力を加速度に
                    double norm1 = (v * v.T)[0, 0];
                    double norm2 = (v * a.T)[0, 0];
                    double norm3 = (a * a.T)[0, 0];
                    double f     = 0;
                    if (norm1 * norm3 != 0)
                    {
                        f = -norm2 / Math.Sqrt(norm1 * norm3);
                    }
                    else if (norm1 == 0)
                    {
                        f = 1;
                    }
                    else
                    {
                        f = -1;
                    }
                    double damping = 0;
                    if (_drift1)
                    {
                        damping = Drift1(f);
                    }
                    else if (_drift2)
                    {
                        damping = Drift2(f);
                    }
                    else if (_drift3)
                    {
                        damping = Drift3(f);
                    }
                    else
                    {
                        damping = Drift0(f);
                    }
                    //damping = 0;
                    full.move(f);
                    dbg = "damping:" + damping.ToString() + "\n" + "dt:" + dt.ToString() + "\n" + "Step#:" + t.ToString();
                    full.setDbgText(dbg);
                    FriedChiken.q.times(damping).Add(dt, FriedChiken.r);
                    double normQ = FriedChiken.q.norm;
                    double K     = normQ * normQ * 0.5;
                    double P     = FriedChiken.energy;
                    double E     = K + P;
                    int    itr   = 0;
                    FriedChiken.x.Add(dt, FriedChiken.q);
                    if (FriedChiken.numCond > 0)
                    {
                        itr = psi();
                    }
                    full.addNorm(K, E, itr, normW, resid);

                    stw.Stop();
                    t++;
                    if (_RP == false)
                    {
                        break;
                    }
                }
                stw.Reset();

                //////////////
                for (int i = 0; i < lfN.Count; i++)
                {
                    Guid[] gs = fixedPointsGuids[i];
                    for (int j = 0; j < gs.Count(); j++)
                    {
                        Rhino.DocObjects.PointObject obj = (Rhino.DocObjects.PointObject)Rhino.RhinoDoc.ActiveDoc.Objects.Find(gs[j]);
                        Rhino.Geometry.Point3d       p   = new Rhino.Geometry.Point3d(obj.PointGeometry.Location.X, obj.PointGeometry.Location.Y, obj.PointGeometry.Location.Z);
                        if (lfN[i].fixX)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 0] = lfN[i].nodeList[j].getNodes()[0, 0] * 0.95 + (p.X - dist) * 0.05; //*
                            if (dist != __dist)
                            {
                                p.X = p.X + dist - __dist;
                            }
                        }
                        else
                        {
                            p.X = lfN[i].nodeList[j].getNodes()[0, 0] + dist;
                        }
                        if (lfN[i].fixY)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 1] = lfN[i].nodeList[j].getNodes()[0, 1] * 0.95 + p.Y * 0.05;//*
                        }
                        else
                        {
                            p.Y = lfN[i].nodeList[j].getNodes()[0, 1];
                        }
                        if (lfN[i].fixZ)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 2] = lfN[i].nodeList[j].getNodes()[0, 2] * 0.95 + p.Z * 0.05; //*
                        }
                        else
                        {
                            p.Z = lfN[i].nodeList[j].getNodes()[0, 2];
                        }
                        double x = 0, y = 0, z = 0;
                        x = p.X - obj.PointGeometry.Location.X;
                        y = p.Y - obj.PointGeometry.Location.Y;
                        z = p.Z - obj.PointGeometry.Location.Z;

                        Rhino.Geometry.Transform tx = Rhino.Geometry.Transform.Translation(x, y, z);
                        gs[j] = Rhino.RhinoDoc.ActiveDoc.Objects.Transform(gs[j], tx, true);
                    }
                }
                if (dist != __dist)
                {
                    __dist = dist;
                }


                foreach (GH_particleSystem pS in lpS)
                {
                    if (pS != null)
                    {
                        if (pS.UPGR != null)
                        {
                            pS.UPGR(dist, 0, 0);
                        }
                    }
                }
            }

            return;
        }
예제 #33
0
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Point to orient from
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point to orient from");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Define source plane
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }
        Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
        source_plane.Origin = gp.Point();

        // Surface to orient on
        Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
        gs.SetCommandPrompt("Surface to orient on");
        gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
        gs.SubObjectSelect             = true;
        gs.DeselectAllBeforePostSelect = false;
        gs.OneByOnePostSelect          = true;
        gs.Get();
        if (gs.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gs.CommandResult());
        }

        Rhino.DocObjects.ObjRef objref = gs.Object(0);
        // get selected surface object
        Rhino.DocObjects.RhinoObject obj = objref.Object();
        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // get selected surface (face)
        Rhino.Geometry.Surface surface = objref.Surface();
        if (surface == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // Unselect surface
        obj.Select(false);

        // Point on surface to orient to
        gp.SetCommandPrompt("Point on surface to orient to");
        gp.Constrain(surface, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Do transformation
        Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
        double u, v;

        if (surface.ClosestPoint(gp.Point(), out u, out v))
        {
            Rhino.Geometry.Plane target_plane;
            if (surface.FrameAt(u, v, out target_plane))
            {
                // Build transformation
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

                // Do the transformation. In this example, we will copy the original objects
                const bool delete_original = false;
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    doc.Objects.Transform(go.Object(i), xform, delete_original);
                }

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
예제 #34
0
 /// <summary>
 /// Is called when the object associated with this data is transformed. If you override this
 /// function, make sure to call the base class if you want the stored Transform to be updated.
 /// </summary>
 /// <param name="transform">The transform being applied.</param>
 protected virtual void OnTransform(Rhino.Geometry.Transform transform)
 {
     UnsafeNativeMethods.ON_UserData_OnTransform(m_pNativePointer, ref transform);
 }