pattern-x / gemini-viewer-examples

Examples and demos for gemini-viewer sdk, which is a WebGL based BIM model viewer, built on three.js. It is used to view dwg/dxf, gltf, obj, ifc models, etc.
205 stars 43 forks source link

Model display size #124

Closed ershuaili closed 7 months ago

ershuaili commented 8 months ago

I want the model to specify its size when it is initially loaded, or have it completely fill the view. How do I set this up?

ershuaili commented 8 months ago

I set "ignorePaperSpace: true," but it doesn't work. image

yanzexuan1 commented 8 months ago

The idea is to get object's bounding box then zoom to it. Can you try this?

ershuaili commented 7 months ago

I have set it viewer.zoomToBBox(bBox); It does zoom in, but it doesn't scale to completely fill the window there is still distance. image

yanzexuan1 commented 7 months ago

Well, it designed to have a margin around. Can you tell me why do you want it to completely fill the window?

You can implement the zoomToBBox() by yourself:

    public zoomToBBox(bbox: THREE.Box3): void {
        const center = bbox.getCenter(tempVec3);
        const sizeX = bbox.max.x - bbox.min.x;
        const sizeY = bbox.max.y - bbox.min.y;
        const leftRightSize = this.camera.right - this.camera.left;
        const bottomTopSize = this.camera.top - this.camera.bottom;
        let targetCameraZoom = Math.min(leftRightSize / sizeX, bottomTopSize / sizeY);
        this.cameraManager.cameraControls.moveTo(center.x, center.y, center.z);
        this.cameraManager.cameraControls.zoomTo(targetCameraZoom);
    }