0

I use the Draw Tool Extension to create objects in my scene. But they are created simply as three objects.js. I want them to be clickable and be part of the Autodesk Forge Viewer model. I'm new to Forge, and I don't understand how to do it or where to read about it at all.

This is how I create objects. This is where I took the extension that I use https://github.getafreenode.com/autodesk-platform-services/aps-extensions/blob/main/public/extensions/DrawToolExtension

        // If left button is pressed and we're not drawing already
        if (button === 0 && this.state === '') {
            // Create new geometry and add it to an overlay
            if (this.mode === 'box') {
                const geometry = new THREE.BufferGeometry().fromGeometry(new THREE.BoxGeometry(1, 1, 1));
                const material = new THREE.MeshPhongMaterial({ color: 0x44bbff });
                this.mesh = new THREE.Mesh(geometry, material);
            } else {
                const geometry = new THREE.BufferGeometry().fromGeometry(new THREE.CyclinderGeometry(0.5, 16, 16));
                const material = new THREE.MeshPhongMaterial({ color: 0x44bbff });
                this.mesh = new THREE.Mesh(geometry, material);
            }
            this.viewer.impl.addOverlay(DrawToolOverlay, this.mesh);
            
            // Initialize the 3 values that will control the geometry's size (1st corner in the XY plane, 2nd corner in the XY plane, and height)
            this.corner1 = this.corner2 = this._intersect(event.clientX, event.clientY);
            this.height = 0.1;
            this._update();
            this.state = 'xy'; // Now we're drawing in the XY plane
            return true; // Stop the event from going to other tools in the stack
        }
        // Otherwise let another tool handle the event, and make note that our tool is now bypassed
        this.bypassed = true;
        return false;
    } ```

1 Answer 1

1

There's actually two ways of adding custom geometry:

  • overlays
    • useful for situations where you don't want the custom geometry to behave like other design elements
    • good for things like custom gizmos, simulation elements, etc.
  • scene builder
    • useful when you do want the custom geometry to behave like other design elements (making it hoverable, selectable, etc.)

It sounds like what you want to use is the scene builder approach.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.