Open irisred opened 9 years ago
in general this should work but i suggest using the renderer.onRender callback rather than using your own requestAnimationFrame. XTK handles this under the hood. and don't add the objects again, just call cube.update()
I do not find the cube.update() function, need I code it myself?
if I change the code like the following image: the result will be:
I just delete the callback, change the cube's center, add the cube into the renderer, and do the subtract.operation, it seems the xtk lib can do the csg operation not only once, but when I add the renderder.onRender() callback,not the requestAnimationFrame(), the cube which center is changed is moving, the result--as(just because the key "a" & "s" are near on the keyboard) doesn't change:
I want to make a static webgl page that use a cube(or any other objects else, like a cylinder) to cut(subtract), union or inverse another object, I'd like to make the cube be used to cut another one animate when time changes, this cube's lengthX or center would change, and when I changed these properties, I use renderer3D.add() to add these objects to the render, and call renderer3D.render() to show it out, but the operation-subtract's result didn't anymore,what should I do?
following is my js code:
var cubeOriginal = null; var renderer = null; var currentTime = null; var cube; var result; function animate() { renderer.render(); if (cubeOriginal.lengthX <20) { cubeOriginal.lengthX += 5; result = cube.subtract(cubeOriginal); cubeOriginal.visible = false; cube.visible = false; renderer.add(cubeOriginal); renderer.add(result); } requestAnimationFrame(animate); } window.onload = function () { // create the X render3D renderer = new X.renderer3D(); renderer.init(); // create the cube and add it to the render3D cubeOriginal = new X.cube(); cubeOriginal.center = [10, 10, 10]; cubeOriginal.color = [0, 1, 1]; cubeOriginal.lengthX = 10; cubeOriginal._lengthX = 5; cubeOriginal.lengthY = 10; cubeOriginal.lengthZ = 10; renderer.add(cubeOriginal); cube = new X.cube(); cube.center = [0, 0, 0]; cube.color = [1, 1, 0]; renderer.add(cube); // and animate!! animate(); };