katopz / jsc3d

Automatically exported from code.google.com/p/jsc3d
0 stars 1 forks source link

How to Add a Ground Plane? #77

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I am planning to add a ground plane to the viewer permanently. I use the viewer 
mainly to display buildings (stl files), so it would be more realistic to have 
the ground. Originally I though I might be able to load multiple stl files on a 
scene(ground plane and a building), but one model could be so large that it 
completely enclose the other. Can you please give me a hint how I can start the 
process? Thank you very much!

Kai L.

Original issue reported on code.google.com by liuwukai...@gmail.com on 22 Jun 2014 at 2:29

GoogleCodeExporter commented 9 years ago
Hi, Liu:

Really good idea! In fact I have been considering providing build-in support 
for this functionality just as that in most CAD tools. But I'm just too busy in 
other projects and there are still some difficulty in implementation to be 
taken into account.

As for your application, a practical solution may be not to import multiple 
models but to compute and construct a ground mesh automatically each time a new 
model is loaded.  The main idea is as this:

An stl model is loaded into one single mesh which makes things simple. When a 
model is loaded completely, its bounding box will be calculated automatically 
and stored in the mesh.aabb property.  By knowing this, we manually construct a 
box mesh whose vertical height is set to a small value and the horizontal 
dimensions can be deduced from the sizes of the bounding box (such as 4 times 
as large as that of the box). The vertices of the mesh should be placed just 
beneath the bottom of the bounding box. Then we add our new mesh into the scene 
via scene.addChild() method and update  the display to show the result.

This approach is based on the assumption that the major model is positioned up 
straight without any rotation in its model space. Otherwise it won't work.

Manually mesh construction is not documented well yet. I think this demo 
http://jsc3d.googlecode.com/svn/trunk/jsc3d/demos/avatar.html can be a 
reference for how to complete the task. And don't forget the API 
documentations: http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/index.html.

Original comment by Humu2...@gmail.com on 27 Jun 2014 at 10:55

GoogleCodeExporter commented 9 years ago
Hi,

Thanks for your explanation.
I'm working on the same project, and after reading through your recommended 
process and other tickets online, I am still having trouble to piece together 
all the needed classes and functions to make this happen.
Would you sketch up a sample code please?

Very much appreciated!
Jay

Original comment by jayzhang...@gmail.com on 23 Jul 2014 at 4:58

GoogleCodeExporter commented 9 years ago
Oh it's not that complicated. I'll send you a simple example to demonstrate how 
to make this via email. Please check it one or two days later.

Original comment by Humu2...@gmail.com on 27 Jul 2014 at 2:14

GoogleCodeExporter commented 9 years ago
Please check the attachment. It demonstrates constructing a ground plane 
according to the bounding box of the scene each time a new model is loaded.

Original comment by Humu2...@gmail.com on 29 Jul 2014 at 10:06

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for your help!
Actually I figured out yesterday and we did approach it in a similar way. 
However, is there anyway that I can have a different color for the ground or 
have the ground surface as a net to better distinguish it from the model loaded?

Thanks

Original comment by jayzhang...@gmail.com on 29 Jul 2014 at 4:29

GoogleCodeExporter commented 9 years ago
Chaging color of the plane is very easy - just create a new 
material(http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/symbols/JSC3D.Material
.html) with the diffuse color you like and set it to the plane via 
mesh.setMaterial() 
(http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/symbols/JSC3D.Mesh.html#setMat
erial).

Making the plane drawn as network requires more coding work. The basic idea is 
to split the large plane to adjacent sub planes, still a single mesh of course. 
And then override the plane mesh's default render mode with 'wireframe' through 
mesh.setMaterial() 
method(http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/symbols/JSC3D.Mesh.html#
setRenderMode), which tells the viewer to always render it as wireframe/network 
regardless what the render mode is for the viewer.  I think it can be done this 
way.

Original comment by Humu2...@gmail.com on 29 Jul 2014 at 5:36

GoogleCodeExporter commented 9 years ago
Thanks a lot, it helps!

Original comment by jayzhang...@gmail.com on 29 Jul 2014 at 7:01

GoogleCodeExporter commented 9 years ago
Actually I tried to change the diffuse color to green, it didn't work. Then I 
found out that for whatever color I changed, it will automatically be black. 
Now I am using the default color, which is brown. Would you mind checking it 
for me?

For the network plane, I totally understand your logic but if it's possible, 
please send me a sample code. Otherwise please don't worry about it.

Also, my code currently could upload multiple stl files on the same ground 
surface. However, to better distinguish different models, is there anyway I can 
change the color of stl model uploaded?

Sorry I asked a lot of question, I appreciate your help!

Original comment by jayzhang...@gmail.com on 30 Jul 2014 at 5:52

GoogleCodeExporter commented 9 years ago
You should not just change the diffuse color of an existing material but create 
a new material with the required diffuse color and set it to the mesh.

Please check the updated demo in the attachment. It may be helpful for your 
current development.

Original comment by Humu2...@gmail.com on 31 Jul 2014 at 10:47

Attachments:

GoogleCodeExporter commented 9 years ago
I didn't use the correct format for color,
Thanks a lot!

Original comment by jayzhang...@gmail.com on 31 Jul 2014 at 4:11

GoogleCodeExporter commented 9 years ago
Hi there again,

I've finished adding ground plane to the model and other related stuff. Again 
thanks for your help. It works very well locally. However, when I tried to push 
the same code to the website, it messed up to an extent. The issue is that what 
the code is doing is adding layers of layers viewer on top of each other if I 
don't refresh the page, because on the web page, we are asking the user to 
upload two STL files at once. In another word, without refreshing the page and 
just changing the uploading files, the outcome is very uncertain. Especially 
when I rotate it, the viewer will show the previous uploaded STL models, not 
the current one.

Thanks,
Jay

Original comment by jayzhang...@gmail.com on 9 Sep 2014 at 11:31