kaosat-dev / CoffeeSCad

DISCONTINUED ! Browser based 3D solid CAD editor, Openscad style, with a Coffeescript based syntax, using only Coffeescript + Javascript
MIT License
226 stars 53 forks source link

Rendering Speed #147

Open Daubsy opened 11 years ago

Daubsy commented 11 years ago

I am working on a complex model. When I make changes, it takes a very long time for the scene to update.

Will local development provide faster rendering speed? Are there any other development tools / workflows that can help with this?

Thanks!

MauricevanLeeuwen commented 11 years ago

Your question is stated in quite vague terms. I suppose you don't refer to the speed of WebGL rendering your model, but to the speed with wich CoffeeSCad rebuilds your model after changing parameters.

I did some tests with OpenJSCad and found at that a lot of the time is spend in the boolean operations due to the model being canonicalized and tessellated. I see that CoffeeSCad reused this code (without mentioning the original author in the licence though? but I don't know a thing about licencing though..) so you will have the same speed issues there.

Even one union on a model with many polygons or vertices will take a substantial amount of time. I suspect doing the tesselation in c++ (or opengl 4.0 .. not supported by webbrowsers) will be quicker. But if we do it with javascript, it doesn't matter if you do it in the browser or locally. Both use the same javascript engine (V8 or SpiderMonkey) on the same machine.

For the workflow: You could split your model and code into parts, and only build and render the parts your working on. But this will not speed up the build times of your complete model, it will only make working on large models easier.

You can also try to not rebuild your complete model on every parameter change. Rather split your code into parts that are evaluated in consecutive order, and have parameters for each part. Then, on parameter change, you don't have to evaluate the code that belongs to earlier parts, but only for the parts that follow after parameter change. Then you might try to do the union operations, or other operations that trigger heavy computation, early in your code, and have parameters that do very simple transformations later in the code...

In pseudo code, imagine the speed you might gain when you only execute the code that is needed for the parameter change:

var doAll = function(param1, param2){
     operation1(param1);
     operation2(param2);     
};
doAll( value1, value2 ); // initially
doAll( value1, value2 ); // on value2 change
var doFirst = function(param1){
     operation1(param1);
};
var doSecond = function(param2){
      operation2(param2);
};
doFirst( value1 );
doSecond (value2); //initially
doSecond (value2); // on value2 change

Can you maybe comment about what slows you down?

kaosat-dev commented 11 years ago

Very complete and correct answer by @MauricevanLeuwen :-)

Spliting things into smaller units / projects helps in this case, but only to a point.

If you could post you code somewhere it would really help with diagnosing the issue more precisely :-)

I am also working on a number of optilisations which should help :

But these improvements are still a few months off (pessimistically)

kaosat-dev commented 11 years ago

Also @MauricevanLeeuwen The fact that coffeescad is/was based on openjscad is clearly stated in the readme :so ;-)

kaosat-dev commented 11 years ago

Woops you meant in the licence file ? Yeah not sure either could add Openjscad's author I guess / other libs too ( lots of them).

Daubsy commented 11 years ago

Thank you for the informative answers! I don't think WebGL processing is the problem. The rendering speed seems mostly affected by number of objects and boolean operations. Even if I change a very insignificant property, Coffeescad takes a long time to update the model (although I guess this could also be the result of poor coding?). I have built a similar model in OpenJScad and it renders and updates much faster when I make changes. Does converting from Coffeescript to Javascript at compile have a significant impact?

MauricevanLeeuwen commented 11 years ago

I'm interested in your code. Could you give an example of code that runs (much) faster in OpenJSCad than CoffeeSCad ?

Daubsy commented 11 years ago

Sure. Im doing something very similar to the gear demo. Try running this code in Coffeescad: https://github.com/zignig/CoffeeSCad-examples/tree/master/applied/Involute

It was adapted from the OpenJScad gear example "Greg's Parametric Involute Gear Script" at openjscad,org, which takes no more than 2 seconds to render. The similar Coffeescad example take almost a minute to render. That has been my experience.

kaosat-dev commented 11 years ago

@Daubster I believe it is not 100% the same code, will check in details, but also, can you please confirm that you have also tried enabling "background processing" in CoffeeSCad ? The conversion time coffee-> js is trivial (not even a few ms in most cases)

kaosat-dev commented 11 years ago

@MauricevanLeeuwen , anyway I can contact you by mail? I got a few things I would love to discuss :)

MauricevanLeeuwen commented 11 years ago

@kaosat-dev see my Gravatar to see my contact info. (start a google hangout)

MauricevanLeeuwen commented 11 years ago

@kaosat-dev found the contact details yet? If you don't want to use google hangouts, what's your preferred alternative?

kaosat-dev commented 11 years ago

@MauricevanLeeuwen sorry about that, had a very busy weekend, thanks for the contact info , added you on g+ (I generally don't use hangouts, but single person message on g+ if that is alright with you :)