Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4146

Trouble w/ Viewport Clipping+ DrawViewportWires

$
0
0

Q1: What am I doing wrong?

I have a component that is Drawing label meshes to the viewport and the labels work great when they are in the midst of other Rhino geometry in the scene. However, I am trying to implement a zDepth functionality that moves the label toward the viewport screen plane, by using a vector to move based on an amount and overriding the BoundingBox of the GH_Component. Unfotrunately, every time I move the label beyond the boundary of existing geometry in the Rhino scene, my label disappears.

Sample code:

public override void ClearData()
        {
            base.ClearData();
            this.tagObjects.Clear();
            this.ClipBox = BoundingBox.Empty;
        }

        public override BoundingBox ClippingBox
        {
            get
            {
                return this.ClipBox;
            }
        }

        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            bool debug = false;
            //args.Display.EnableClippingPlanes(false);
            int pIndex = 0;

            foreach (LabelContents mto in tagObjects)
            {
                
                TagStyle tts = mto.TagStyle;
                RhinoViewport viewport = args.Viewport;
                //Calculate change of basis from world origin to the camera plane
                Transform cameraXform = new Transform();
                // Get camera plane and set it to the Tag Origin
                Plane cameraPlaneRaw;
                args.Viewport.GetCameraFrame(out cameraPlaneRaw);
                //double length = towardLensVector.Length;
                Plane cameraPlane = new Plane(cameraPlaneRaw);
                cameraPlane.Origin = mto.TagOrigin;
                //cameraPlane.Translate(towardLensVector * tts.ZDepth);  // disabled while clipping plane issue is resolved
                //Plane nearClippingPlane = new Plane();
                Plane farClippingPlane = new Plane();
                //Circle debugCircle = new Circle(farClippingPlane, 100);
                //debugCircle.Translate(towardLensVector * tts.ZDepth);
                //args.Display.DrawCircle(debugCircle, Color.Black); // debug
                //args.Viewport.GetFrustumNearPlane(out nearClippingPlane);
                args.Viewport.GetFrustumFarPlane(out farClippingPlane);

                Vector3d towardLensVector = new Vector3d(args.Viewport.CameraLocation - mto.TagOrigin);
                towardLensVector.Unitize();
                Vector3d parallelVector = farClippingPlane.Normal;
                Vector3d zDepthVector = (args.Display.Viewport.IsParallelProjection) ? parallelVector : towardLensVector;
                zDepthVector.Unitize();
                Point3d origin = mto.TagOrigin + zDepthVector * tts.ZDepth;
                cameraPlane.Origin = origin;
                Sphere clippingSphere = new Sphere(cameraPlane, 15);
                ClipBox.Union(clippingSphere.BoundingBox);
                args.Display.DrawSphere(clippingSphere, Color.Black);
...
}

Q2: What is the difference between DrawViewportMeshes and DrawViewportWires? They both seem to function the same way.

Thanks!

7 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 4146

Trending Articles