Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

crop particular room/area from the forge viewer based on Revit coordinates(min and max X, Y, Z)

We are using forge viewer(v7) in our web application.

Our requirement is to crop particular room/area from the forge viewer. For example, if we have shown a house model in the forge viewer then if a user select a kitchen(from menu or navbar) then the viewer should show only kitchen area (including all its objects like cabinets, burner, fridge, sink etc.) and all other objects/sections should be hidden. Similarly for bedrooms, baths etc. It will be just for viewing purpose at run time and not for any automation.

We are getting room coordinates(min and max X, Y, Z) with the help of following using forge API(with Revit engine).

GeometryElement geoElement = room.ClosedShell;
BoundingBoxXYZ boundingBox = geoElement.GetBoundingBox();
XYZ min = boundingBox.Min;
XYZ max = boundingBox.Max;

We are using viewer.setCutPlanes function to draw cutplanes in viewer.

            var minPt = new THREE.Vector3(x,y,z); //!<<< put your point here
            var maxPt = new THREE.Vector3(x,y,z); //!<<< put your point here

            const normals = [
                new THREE.Vector3(1, 0, 0),
                new THREE.Vector3(0, 1, 0),
                new THREE.Vector3(0, 0, 1),
                new THREE.Vector3(-1, 0, 0),
                new THREE.Vector3(0, -1, 0),
                new THREE.Vector3(0, 0, -1)
            ];

            const bbox = new THREE.Box3(minPt, maxPt);
            const cutPlanes = [];

            for (let i = 0; i < normals.length; i++) {
                const plane = new THREE.Plane(normals[i], -1 * maxPt.dot(normals[i]));

                // offset plane with negative normal to form an octant
                if (i > 2) {
                    const ptMax = plane.orthoPoint(bbox.max);
                    const ptMin = plane.orthoPoint(bbox.min);
                    const size = new THREE.Vector3().subVectors(ptMax, ptMin);
                    plane.constant -= size.length();
                }

                const n = new THREE.Vector4(plane.normal.x, plane.normal.y, plane.normal.z, plane.constant);
                cutPlanes.push(n);
            }
            viewer.setCutPlanes(cutPlanes);

But when we are passing these coordinates (obtained for API) to this front end JS code the cutPlanes are getting created at incorrect position/points. For example when we are passing coordinates of kitchen its cropping the small portion of roof and same with all other room.

The possible reason is that the Revit & forge viewer coordinates are not same.

Does anyone have an idea that how can we map these Revit coordinates with forge viewer and draw cutplanes?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're following the Forge Viewer tutorial to load the model, then you need to subtract global offsets from endpoints of the room bounding box like below:

var minPt = new THREE.Vector3(x,y,z); //!<<< put your point here
var maxPt = new THREE.Vector3(x,y,z); //!<<< put your point here

var offsetMatrix = viewer.model.getData().placementWithOffset;
var offsetMinPt = minPt.applyMatrix4(offsetMatrix); 
var offsetMaxPt = maxPt.applyMatrix4(offsetMatrix);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...