Closed gero3 closed 11 years ago
Recursion!
With Three.js's stl loaders and renderers, it mustn't have been much work for them. :-)
They edited the stlloader at least a bit. I'm not sure what yet.
It would be pretty handy if they did the same for OBJ, DAE, etc :) We need more loaders! 3DS, DXF, VRML, ...
It would be even nicer if they did implement support for 3D CAD Format such as STEP IGES or OpenCASCADE Brep using node-occ
It seems like they did some interesting changes(not really sure if they started from scratch or not):
- They download the content as string instead of arraybuffer.
- They have a special binaryreader for the conversion
That's cool. Currently the editor can't load STL files because of that. All the other loaders use string but STLLoader
(and PLYLoader
) relies on arraybuffer xhr. Maybe it would be better using their approach.
@skalnik are you guys planning open sourcing or upstreaming the loader?
Sure, I can clean it up and submit a patch.
@sshirokov Sweet!
FYI, @gero3 managed to to rescue some of the bits you guys have implemented: https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/STLLoader.js
@sshirokov
Do you mind if I ask why something is implemented like it is in github implementation??
Sure. What's up?
This piece of code:
I understand that it creates new vectors but it could be a lot smaller.
normal = (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(THREE.Vector3, readFloat3(), function(){});
for (_j = 1; _j <= 3; _j++) {
geometry.vertices.push((function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(THREE.Vector3, readFloat3(), function(){}));
}
Sorry, the original code is written in CoffeeScript, so that's the compiled result from the asset pipeline. That section looks more like this originally
normal = new THREE.Vector3 readFloat3()...
for [1..3]
geometry.vertices.push new THREE.Vector3 readFloat3()...
Which is a lot nicer on the eyes. I can port the code back over to more idiomatic JS, or include both the .coffee
and .js
versions. Though, I think pure JS would be ideal since the rest of Three.js is not a Coffee project at all.
Here's the original loader file in full in the original Coffee: stlloader.coffee
It's basically a port of Three.js's examples/js/loaders/STLLoader.js
into Coffee with a few tweaks.
Let me know if any parts are unclear, of if you'd still like me to do the pure-JS port. You seem to be off to a pretty solid start.
parseFloat()
wrappers in the ASCII parser that prevent the mathematics from suddenly becoming string additions during translation.<0,0,0>
and this largely okay according to the de-facto format.@sshirokov Btw, as a side note... I think you guys should enable antialias :)
new THREE.WebGLRenderer( { antialias: true } )
@sshirokov
I think I have everything now. The only things left is to remove some of the logic that the coffeescript compiler added. And then it seems we'll have a decent STLLoader. There are some additional notes we have to pay attention on.
These are of course only my opinions.
PS: The changes I did are some what documented in the commits of following repository => https://github.com/gero3/threejs_STLLoader
There is a new blogpost from github where three.js gets used to demo stl files on all repositories.
https://github.com/blog/1465-stl-file-viewing