问题
I need to create a vertical section plane leaning against a selected object. For example selecting an object like this
I need to get a section plane leaning against the longest side of the object
I'm using the viewer version 7.16 that offers a Section plane option in the right click selection but it works incorrectly.
I am using the frags.getWordBounds method to get the box "around" the object and, using a little trigonometry, I have calculated the orientation, but I guess it's not the right approach because I cannot determine the right object direction:
+-------------+
|. *|
| . * |
| . * |
| . * |
| . * |
| . * | is my object the dot or the asterisk?
| * |
| * . |
| * . |
| * . |
| * . |
| * . |
|* .|
+-------------+
Thanks in advance for any support.
回答1:
I'm using the viewer version 7.16 that offers a Section plane option in the right click selection but it works incorrectly.
Thanks for letting us know the issue - Is it possible for you to upload the offending model to an online drive and drop the download link to forge.help@autodesk.com with a little more description about how it didn't work correctly so we can try to fix it?
And looks like you are trying to implement something of your own to replace the sectioning option why not capture the mouse click events on the canvas by implementing your own tool and go from there to calculate the cutplanes using the hit test results? Something like:
const hitTest = viewer.hitTest(event.x,event.y)
const SectionTool = viewer.getExtension("Autodesk.Section")
SectionTool.activate()
SectionTool.tool.setSectionPlane(hitTest.face.normal, hitTest.point)
回答2:
I had a similar issue when creating my own section plane tool. You can see question here: Getting global normal from hitTest.face.normal
Not sure if you are creating you own, but if you are i found that two things were crucial for me:
onst normal = this.hitTest.face.normal.clone();
normal.transformDirection( this.hitTest.object.matrixWorld );
and
const currentFragId = this.hitTest.fragId;
const renderProxy = this.viewer.impl.getRenderProxy(this.viewer.model,currentFragId);
The first snippet gets world normal from object space to world space, second snippet seems to recalculate the fragment received in hitTest.
来源:https://stackoverflow.com/questions/61654483/create-a-section-plane-leaning-against-one-object