xtk / X

The X Toolkit
http://www.goXTK.com
Other
795 stars 266 forks source link

what should I do, there is some trouble in using the Xtk lib. #170

Open irisred opened 9 years ago

irisred commented 9 years ago

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(); };

haehn commented 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()

irisred commented 9 years ago

I do not find the cube.update() function, need I code it myself?

irisred commented 9 years ago

if I change the code like the following image: qq 20150125220453 the result will be: qq 20150125221252

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: qq 20150125222423

qq 20150125222512