0

How can I pass values dynamically generated from dat.gui sliders into the p and q properties of TorusKnotGeometry, like in this example? http://threejs.org/docs/#Reference/Extras.Geometries/TorusKnotGeometry

I tried looking through the source code but didn't understand how to apply it: http://threejs.org/docs/scenes/js/geometry.js

Here's what I tried. I have cube rotation rendering properly, but torus is not rendering with the values from sliders.

        var p = guiControl.p;
        var q = guiControl.q;
        // setup torus and add to scene
        var torusGeometry = new THREE.TorusKnotGeometry(0.64, 0.25, 25, 6, p, q);
        var torusMaterial = new THREE.MeshLambertMaterial({color: 0xff00ff});
        var torus = new THREE.Mesh(torusGeometry, torusMaterial);
        torus.position.set(1,1,1);
        torus.castShadow = true;
        scene.add(torus);



        function render(){
            requestAnimationFrame(render);
            // controls.update();

            cube.rotation.x += guiControl.rotationX;
            cube.rotation.y += guiControl.rotationY;
            cube.rotation.z += guiControl.rotationZ;

            torusGeometry.parameters.p += guiControl.p;
            torusGeometry.parameters.q += guiControl.q;

            renderer.render(scene,camera);
        };

        render();

Thanks for your help! I'm new to this.

gman
  • 100,619
  • 31
  • 269
  • 393
grace
  • 73
  • 7
  • I think you will have to recreate the geometry when the slider value changes – 2pha Aug 05 '16 at 22:50
  • @grace: `TorusKnotGeometry()` and `updateGroupGeometry()`, which properly calls `dispose()` on the old geometry, are the key methods in the source code you linked to. Step through with the debugger. – WestLangley Aug 06 '16 at 00:22

0 Answers0