![]() |
|
Instanced WireBoxVisual3D - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab3d.DXEngine (https://forum.ab4d.com/forumdisplay.php?fid=11) +--- Thread: Instanced WireBoxVisual3D (/showthread.php?tid=4290) |
Instanced WireBoxVisual3D - siik - 10-06-2021 Hi, I can see there are various ways to display instanced data, however I'm struggling to be able to instance WireBoxVisual3D. The samples show the following:
Is this possible? Any help is appreciated. RE: Instanced WireBoxVisual3D - abenedik - 10-06-2021 It is not possible to render many instances of 3D lines. This would require a new shader and an update to the ThickLineEffect. But you have the following options: 1) WireBoxVisual3D is rendered by using 3D lines (a geometry shader is used to generate the 3D lines with specified line thickness and in such a way that they are always facing the camera). But instead of that, you can create 3D lines from line tubes - that are fixed MeshGeometry3D objects that are not changed when the camera is changed but when rendered as solid color (or as emissive material) that is not shaded by light that can be used as 3D lines - see example in Ab3d.PowerToys samples project: Note that there you do not specify the line thickness that is defined in screen coordinates regardless of the camera, but you set tube radius in 3D world coordinates - so the lines will get visually thinner when the camera is moving away. You can generate tube lines mesh by using Ab3d.Meshes.TubeLineMesh3D and Ab3d.Meshes.TubePathMesh3D. You can combine meshes by Ab3d.Utilities.MeshUtils.CombineMeshes. This will give you a single MeshGeometry3D that can be used for instancing with InstancedMeshGeometryVisual3D. To prevent shading the meshes, you need to render them with a solid color - set IsSolidColorMaterial on InstancedMeshGeometryVisual3D to true. 2) You can render instanced objects as wireframe objects instead of as solid models. To do this you will need to set the OverrideRasterizerState on the RenderObjectsRenderingStep to DXDevice.CommonStates.WireframeMultisampleCullNone. This is a more advanced customization. This required to create another RenderObjectsRenderingStep and add it before the DefaultRenderObjectsRenderingStep. Then for the new RenderObjectsRenderingStep set the OverrideRasterizerState to XDevice.CommonStates.WireframeMultisampleCullNone and set FilterRenderingQueuesFunction to render only ComplexGeometryRenderingQueue. You also need to update the DefaultRenderObjectsRenderingStep by setting the FilterRenderingQueuesFunction to the function that will render all rendering queues except ComplexGeometryRenderingQueue. In the InstancedMeshGeometry3DTest.xaml sample from Ab3d.DXEngine samples this can be achieved by using the following code (add that into the constructor): Code: MainDXViewportView.DXSceneInitialized += delegate (object sender, EventArgs args)The screenshot of this can be seen here: Disadvantages of this technique:
3) Use many WireBoxVisual3D objects. Ab3d.DXEngine uses multi-threading and DirectX commands caching and can render many individual 3D objects very fast. To optimize that you can convert many WireBoxVisual3D into a single MultiLineVisual3D where you manually define the 3D positions for all lines for all wire boxes. You can start with defining 3D lines for one 3D wire box with center position at (0, 0, 0) and size (1, 1, 1). This would define the default lines. Then for each instance of wire box (instance in the InstanceData) transform the positions of the default lines by the WorldMatrix. The following code can be used to do that: Code: InstanceData[] allInstancesData = new InstanceData[1000];If you are not changing the world matrices very often then this is in my opinion the preferred way to show 3D lines. If you change the matrices often, then this would require to regenerate the allInstancedWireBoxesPositions. In this case you need to decide if you can optimize this code or use options (1) or (2) RE: Instanced WireBoxVisual3D - siik - 10-08-2021 Thanks for the response! I thought it might be something like that, thank you for providing alternatives. |