Open GoogleCodeExporter opened 9 years ago
Your code is basically correct. In my own test, both models are loaded without
error. The problem is one model is so large that it completely enclose the
other. JSC3D does not support additional transformations for each mesh, so
multiple models form different sources can be used in a scene only if they are
positioned and scaled properly in the same space to work together.
Changing model color is rather easy. Just create a new material for each mesh
with the colors wanted, then set them to corresponding meshes through the
JSC3D.Mesh.prototype.setMaterial() method. See the following snippet:
...
// this changes the model color to red
mesh.setMaterial(new JSC3D.Material('red-material', 0, 0xff0000));
...
viewer.update();
...
Original comment by Humu2...@gmail.com
on 16 Dec 2013 at 6:46
Attachments:
Thanks a lot ! Indeed I thought my models had the same size. So it works ! :-)
I'm trying to set colors on my models. I added your snippet in the
onModelLoaded function, using a color array :
var colors = [0xff0000, 0x0000ff, 0x00ff00, 0xffff00, 0x00ffff];
var onModelLoaded = function(scene) {
var meshes = scene.getChildren();
for (var i=0; i<meshes.length; i++) {
theScene.addChild(meshes[i]);
meshes[i].setMaterial(new JSC3D.Material('red-material', 0, colors[i]));
}
if (++numOfLoaded == components.length)
viewer.replaceScene(theScene);
};
But all models are red...
I missed something ?
Original comment by nathap...@gmail.com
on 16 Dec 2013 at 11:50
The onModelLoaded callback will be invoked each time a new model is coming. Its
implementation should be changed slightly:
var onModelLoaded = function(scene) {
var meshes = scene.getChildren();
// there should be only one mesh for an STL
if (meshes.length > 0) {
meshes[0].setMaterial(new JSC3D.Material('red-material', 0, colors[numOfLoaded]));
}
if (++numOfLoaded == components.length)
viewer.replaceScene(theScene);
};
The new one will be ok.
Original comment by Humu2...@gmail.com
on 17 Dec 2013 at 3:17
Thanks for your answer.
Unfortunately it doesn't work with this code. Nothing apperas on the view.
I attached my test code, feel free to try it.
Original comment by nathap...@gmail.com
on 17 Dec 2013 at 8:06
Attachments:
[deleted comment]
Problem solved !
This code works :
var onModelLoaded = function(scene) {
var meshes = scene.getChildren();
// there should be only one mesh for an STL
for (var i=0; i<meshes.length; i++) {
theScene.addChild(meshes[i]);
if (meshes.length > 0)
meshes[0].setMaterial(new JSC3D.Material('red-material', 0, colors[numOfLoaded]));
}
if (++numOfLoaded == components.length)
viewer.replaceScene(theScene);
};
I sugest to add instructions about multiple stl loads and colors in getting
started section, because it's very useful !
Original comment by nathap...@gmail.com
on 17 Dec 2013 at 8:26
Attachments:
Nice! Thanks for your suggestion!
Original comment by Humu2...@gmail.com
on 18 Dec 2013 at 2:06
You're welcome !
Hmm, I have last question : Is it possible to load displays each file as soon
as it's loaded ? Currently, the files are displayed simultaneously.
Original comment by nathap...@gmail.com
on 18 Dec 2013 at 8:55
Yes of course. Instead of waiting for all models to be ready, this time just
create the scene object as the 1st model is done. Then add the model to the
scene and pass the scene to viewer. For each model other than the 1st one, when
it's loaded completely, add it into the current scene, whose bounding box
should then be updated manually:
// when a new mesh is coming
...
mesh.init();
theScene.addChild(mesh);
theScene.calcAABB();
viewer.update();
...
The scene.calcAABB() method computes the new bounding box of an existing scene.
This is necessary to ensure a correct rotation pivot.
Original comment by Humu2...@gmail.com
on 18 Dec 2013 at 12:28
Hello,
A question to build onto the original problem. I am trying to load multiple
stl files in a scene, with multiple scenes / canvases on the page.
If I code each scene separately, as you wrote above, then everything works
fine. However, the ideal would be to have the whole thing run off a counter,
creating x scenes as needed. When I do this there are two issues I run into.
First, this code runs through the counter in the first alert and then moves to
the "onModelLoaded" section, where j is undefined. How can I get j to carry
through to the "onModelLoaded" section.
Second, In defining the "components" array as components[1] = 1,2,3 and
components[2] = 4,5,6 they are actual loaded as scene1=1,2,3 and scene2=5,4,6.
I'm not sure if this is related to the "onModelloaded" section or the "loader"
section. For the "loader" section the behavior is the same whether it is in a
for loop (j) or hard coded.
Thanks for any help you can provide.
Original comment by madb...@gmail.com
on 9 Jul 2014 at 9:09
Attachments:
Original issue reported on code.google.com by
nathap...@gmail.com
on 16 Dec 2013 at 4:39