When the entities are very far from the origin their appearance on screen may become very compromised, and the camera may shake badly when moving/rotating the view.
Case 1:
See the image below of a circle created at (1e9, 1e9, 0) with radius 200:
This is due to the float precision of OpenGL that isn't enough to represent coordinates very far from the origin.
To fix this issue you need to:
- Translate the entities back to the origin, put them into a block and add a BlockReference that refers to that block.
- Translate the BlockReference back to the original position far from the origin.
devDept.Eyeshot.Entities.Region circ = devDept.Eyeshot.Entities.Region.CreateCircle(Plane.XY, 1e9, 1e9, 200);
var myMesh = circ.ConvertToMesh(0.1, Mesh.natureType.Plain);
myMesh.Translate(-1e9, -1e9, 0);
myMesh.ColorMethod = colorMethodType.byParent;
Block myBlock = new Block("block");
myBlock.Entities.Add(myMesh);
design1.Blocks.Add( myBlock);
BlockReference myBr = new BlockReference(1e9, 1e9, 0, "block", 0);
design1.Entities.Add(myBr, Color.Red);
See the result below:
Case 2:
Of course, if you have a set of entities, and not just one, that is very far from the origin, the best thing is to compute the center of their bounding box, translate them all of the negative of that quantity and put them in a single block.
Below you can see how to apply this method to the entities read from a .dwg file that are positioned very far from the origin:
ReadAutodesk rd = new ReadAutodesk(@"test.dwg");
rd.DoWork();
// Create a BlockReference with the content of the dwg (the "myDwg" block with all the entities is automatically added to the viewportLayout.Blocks)
BlockReference br = rd.CreateXRef("myDwg", new Point3D(0, 0, 0), design1);
// Add the BlockReference to the viewportLayout so that its bounding box is properly computed
design1.Entities.Add(br);
// Compute the center of the bounding box
Point3D boxMid = (br.BoxMin + br.BoxMax) / 2;
Block block = design1.Blocks["myDwg"];
// move the entities inside the block back to the origin
foreach (var ent in block.Entities)
{
ent.Translate(-boxMid.X, -boxMid.Y, -boxMid.Z);
}
// apply the translation to the blockreference
br.Translate(boxMid.X, boxMid.Y, boxMid.Z);
design1.Entities.Regen();
Note:
Since build 8.0.372 you can call design1.RemoveJittering() to automatically do the steps explained above on the selected entities (put the entities inside a Block, move them to the origin, create a BlockRefrence that moves the block back to its original position).
Below you can see how to change the above code snippets:
Case 1:
devDept.Eyeshot.Entities.Region circ = devDept.Eyeshot.Entities.Region.CreateCircle(Plane.XY, 1e9, 1e9, 200);
var myMesh = circ.ConvertToMesh(0.1, Mesh.natureType.Plain);
design1.Entities.Add(myMesh, Color.Red);
// Set the entity as selected
myMesh.Selected = true;
// Call RemoveJittering() that will put the selected entities into a BlockReference.
design1.RemoveJittering("myBlock");
Case 2:
ReadAutodesk rd = new ReadAutodesk(@"test.dwg");
rd.DoWork();
// Create a BlockReference with the content of the dwg (the "myDwg" block with all the entities is automatically added to the viewportLayout.Blocks)
BlockReference br = rd.CreateXRef("myDwg", new Point3D(0, 0, 0), design1);
// Add the BlockReference to the viewportLayout so that its bounding box is properly computed
design1.Entities.Add(br);
// Call RemoveJittering() by passing the BlockReference just created.
design1.RemoveJittering(br);
Previous versions of this article: Eyeshot 7, Eyeshot 8
Comments
Please sign in to leave a comment.