AnyCAD三维控件

AnyCAD三维控件

  • Docs
  • Download
  • Showcase
  • About

›Get Started

Get Started

  • Overview
  • Features
  • Hello World .Net
  • Modeling Concepts
  • Visualization Concepts
  • Data Exchange

Showcase

  • CAD
  • CAM
  • CAE
  • BIM
  • Robot

Reference

  • API
  • Samples in github

Visualization Concepts

AnyCAD SDK provides you the 3D control with default visualization styles, and of course you can customize it with your own favorites.

View settings

There are many settings can help you to make your 3D application looks different. The related APIs are RenderWindow3d and View3d, you can access the View3d instance via the property of RenderWindow3d::View3d.

Background color

RenderWindow3d::SetBackgroundColor(top, middle, bottom)

e.g:

ColorValue clr = new ColorValue(.5f, .5f, 0.5f)

Show/Hide drawing grid

RenderWindow3d::ShowWorkingGrid(bool)

Set the camera view

RenderWindow3d::SetStandardView(EnumStandardView nType)

EnumStandardView :
   - SV_Invalid,
   - SV_Front,
   - SV_Back,
   - SV_Top,
   - SV_Bottom,
   - SV_Left,
   - SV_Right,
   - SV_ISO

You can also use RenderWindow3d::LookAt function to set arbitrary direction for the camera.

Set Display Mode

RenderWindow3d::SetDisplayMode(int style)

EnumDisplayStyle:
DS_Face      
DS_Wireframe 
DS_Realistic 
DS_Vertex    
DS_Edge      

You can combine these bit flags:

int style = (int(EnumDisplayStyle.DS_Face | EnumDisplayStyle.DS_Edge));

Set Pick Mode

RenderWindow3d::SetPickMode(int nMode)

EnumPickMode:

RF_None        
RF_Face        
RF_Edge        
RF_Vertex      
RF_BBox        
RF_SceneNode   
RF_GroupSceneNode

You can combine these bit flags:

int pickMode = (int(EnumPickMode.RF_Face | EnumPickMode.RF_Edge));

You can set to pick the whole object, then you need to set RF_SceneNode|RF_Edge:RF_Face; You can also set to pick the a group of objects (GroupSceneNode), you need to set RF_ GroupSceneNode |RF_Edge:RF_Face.

Scene Management

Visualize TopoShape Geometry

TopoShape cylinder = GlobalInstance.BrepTools.MakeCylinder(Vector3.ZERO, Vector3.UNIT_Z, 50, 100, 0);

// 0.1f is the precision for visualization.
EntitySceneNode sceneNode = GlobalInstance.TopoShapeConvert.ToEntityNode(cylinder, 0.1f)
sceneNode.SetId(myId);
renderView.SceneManager.AddNode(sceneNode);

Create Group Node

You can create a group of node to set the visible/style/selection…

            TopoShape cylinder = GlobalInstance.BrepTools.MakeCylinder(Vector3.ZERO, Vector3.UNIT_Z, 50, 100, 0);
            TopoShape sphere = GlobalInstance.BrepTools.MakeSphere(new Vector3(0, 0, 150), 50);
            // Create group
            GroupSceneNode group = new GroupSceneNode();
            group.AddNode(GlobalInstance.TopoShapeConvert.ToEntityNode(cylinder, 0.1f));
            group.AddNode(GlobalInstance.TopoShapeConvert.ToEntityNode(sphere, 0.1f));

            //Show the group
            renderView.SceneManager.AddNode(group);

Set Node Style

You can

  • set the face style, line style and vertex style for a SceneNode/GroupSceneNode,
  • Set an Id/name
  • Set the visibility of the node
            // Set transparent face
            FaceStyle style = new FaceStyle();
            style.SetColor(new ColorValue(0.5f, 0.3f, 0, 0.5f));
            style.SetTransparent(true);
            sceneNode.SetFaceStyle(style);

Query selected geometry

After pressing the mouse button, you can use SelectedElementQuery to check selected shape or node by calling RenderWindow3d.QuerySelection(context):

             SelectedElementQuery context = new SelectedElementQuery();
            renderWindow.QuerySelection(context);
            // Get the sub geometry, such as Face, Edge,Vertex
            TopoShape subShape = context.GetSubGeometry();
            // Get the main shape   
 TopoShape shape = cotext.GetGeometry()
            // Get the node id
            int nodeId = context.GetNodeId();

You can use the node id to find other data in your database.

You can use RenderWindow3d::Renderer::QueryHighlight(context) to get the highlighting objects.

Coodinate Conversion

World point to screen point (3D->2D)

Using View3d::WorldPoint2ScreenPoint you can convert the 3D world point to screen 2D point directly. Renderer::WorldPoint2ScreenPoint

Screen point to world point (2D – 3D)

You can map the screen 2d point to 3d world point on the working plane directly via Renderer:: ProjectOnWorkingPlane, Vector3 Renderer:: ProjectOnWorkingPlane(Vector2 mousePt, Vector3 defalutPt)

If the no point if found with the working plane, defaultPt will be returned.

And you can also create your own camera ray and use the ray to get the intersection point with any plane. Ray Renderer::ComputeScreenRay(int cx, int cy)

e.g:

Ray ray = Renderer.ComputeScreenRay(100,200);
Vector3 worldPt = ray.Intersect(Vector3.Zero, Vector3.UNIT_Z);

Pick

The RenderWindow3d control provides the function to compute the 3D point on the working grid:

Vector3 RenderWindow3d::HitPointOnGrid(int cx, int cy)

You can also get the point on the shape:

PickHelper RenderWindow3d::PickShape(int cx, int cy)

You can use PickHelper to get the selected shape and the point on the shape.

← Modeling ConceptsData Exchange →
AnyCAD三维控件
Docs
Getting StartedSamplesAPI Reference
More
BlogGitHubYouku
Copyright © 2006~2019 AnyCAD Graphics Solution.