Jump to content
  • Advertisement
Sign in to follow this  
giugio

sketchup importer

This topic is 2695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello.
I'm trying to import meshes from SketchUp to my c++ application in opengl.
I would use the SketchUp sdk in c++.
I not understand two things:
1)I see that SketchUp seems face oriented and not mesh oriented(i can get all faces in the document ) , how i can create meshes from it? I see that there is a group property ....
I could use a mesh for each face but it seems bad , dont thinks?
2)what is the method for resolve the back material and front material ? i must create two faces in opengl?

thanks

Share this post


Link to post
Share on other sites
Advertisement

2)what is the method for resolve the back material and front material ? i must create two faces in opengl?

OpenGL differentiates between front and back face material. E.g. when dealing with glMaterial there is a face parameter. See e.g. this manual page. If you're using a version of OpenGL where glMaterial is deprecated then you can write your shaders as you like anyway.

Share this post


Link to post
Share on other sites

[quote name='giugio' timestamp='1299338112' post='4782069']
2)what is the method for resolve the back material and front material ? i must create two faces in opengl?

OpenGL differentiates between front and back face material. E.g. when dealing with glMaterial there is a face parameter. See e.g. this manual page. If you're using a version of OpenGL where glMaterial is deprecated then you can write your shaders as you like anyway.
[/quote]

thanks, you have a link or a hint for build a shader with front/back material?

Share this post


Link to post
Share on other sites

[quote name='haegarr' timestamp='1299344288' post='4782105']
[quote name='giugio' timestamp='1299338112' post='4782069']
2)what is the method for resolve the back material and front material ? i must create two faces in opengl?

OpenGL differentiates between front and back face material. E.g. when dealing with glMaterial there is a face parameter. See e.g. this manual page. If you're using a version of OpenGL where glMaterial is deprecated then you can write your shaders as you like anyway.
[/quote]

thanks, you have a link or a hint for build a shader with front/back material?
[/quote]
i'm not understand how draw two material on the same face , one front and one back.

Share this post


Link to post
Share on other sites
What to do exactly depends...

You wrote to use shader scripting. So, from a more theoretical point of view:

1. Draw in 2 passes, one that culls the front faces and hence draws all the faces seen from back, and one that culls backfaces and hence draws all the faces seen from front, using the glCullFace routine. Face culling is done behind the vertex shader but before the fragment shader. Hence all vertices pass the vertex shader. For lighting calculations on back faces it would probably be necessary to invert the normal what could be done in the vertex shader. Because you draw all front faces or back faces, resp., in their own batch, you can use 2 slightly different vertex shaders for this job. You can use 2 slightly different fragment shaders, too, or you alter the texture setup between the 2 draw calls. Or else you pass a flag from the vertex shader to the fragment shader, so the latter is able to pick the correct uniforms and samplers on the fly. There is a build-in read-only variable gl_FrontFacing available in the fragment shader, but I haven't looked for what GLSL versions that flag is valid.

2. Draw in 1 pass with a vertex shader that detects whether the face is seen front or back. The usual way would be to investigate the normal after its transformation into eye space (front/back is a property in eye space, of course). The vertex shader then still inverts the normal. In this solution you are required to pass a flag to the fragment shader, as described above.

3. I think you can invert the normal in the fragment shader, too, if you have the said flag available, but that may be less efficient.

Share this post


Link to post
Share on other sites
Thanks.
But i not understand all.
i try to create an importer from sketchup and in sketchup sdk have a mesh with geometry and material(shader that use for that mesh).
Each material have a two texture , one for back and one for front face and two colors.
1-2)i suppose that if i find a front face, i must use texturefront and front material while if i find a back face i use textureback and colorback, but this is must do in two pass or in two drawing call.
but i must change the shader texture in the shader or use two textures and go to read from one or from another?

for the determination if a face is front or back i can use this formula:
cosine = mul(modelViewInvTrans,float4(Norm,1.0)).z;

where cosine is the cosine of angle between the camera vector and the normal vector.
and if i find <0 or >0....

ps.
how i can send a flag from vertex shader to texture shader?
i'm get this response:
http://www.gamedev.net/topic/598223-send-a-flag-from-vertex-shader-to-fragment-shader/
thanks.

Share this post


Link to post
Share on other sites

...
1-2)i suppose that if i find a front face, i must use texturefront and front material while if i find a back face i use textureback and colorback, but this is must do in two pass or in two drawing call.
but i must change the shader texture in the shader or use two textures and go to read from one or from another?

If you use the 2 pass method where you render in the 1st all back-faces at once and in the 2nd pass all front-faces at once, then you obviously don't need to feed both the front and the back material parameters to the shader. Simply set the back-face material parameters at the beginning of the 1st pass, and set the front-face material parameters at the beginning of the 2nd pass.

If, on the other hand, you use a single pass, then both materials must be available simultaneously, and the shader must select the one parameters set (e.g. the texture) at runtime. That is where the flag is good for at all.


for the determination if a face is front or back i can use this formula:
cosine = mul(modelViewInvTrans,float4(Norm,1.0)).z;

where cosine is the cosine of angle between the camera vector and the normal vector.
and if i find <0 or >0....

ps.
how i can send a flag from vertex shader to texture shader?
i'm get this response:
http://www.gamedev.n...ragment-shader/
thanks.

The aforementioned, build-in gl_FrontFacing flag is available. I assume that Cg provides an equivalent. It unburdens you from a couple of nasty stuff.

Share this post


Link to post
Share on other sites
Hello.
I grouped all the meshes in an unique mesh , multiplying each point of each mesh for the relative word matrix.
I created a texture atlas for each texture and offsetting the uvs
Now i have a lot of different colors for each mesh that don't have a texture but only a color.
I think to use two grouped different meshes , one for all the color meshes and one for all the textured meshes.
for the texture is ok.
But is possible to send the color of each mesh in a vertex buffer var?
because i must send the diffuse,ambient,specular and alpha components.
I see that is possible to group an RGB in a long , can use a float4 for send all(R,G,B,A)?
The next problem is that i have only a color ort two(back color ,front color)for each mesh and not a color for each point , there is a big redundancy.
The alternative is to send the colors via constant buffer , but if i have a lot of colors how i can remedy?
can i use a texure with all colors?
I use opengl 2.

thanks

Share this post


Link to post
Share on other sites
Not sure whether I've understood the problem totally.

If you have a couple of colors that are constant for the entire mesh, then you can push them into the Cg script. In GLSL it would look like


uniform vec4 diffuseColor;
uniform vec4 specularColor;
...

and in GL the appropriate glGetUniformLocation and glUniform4fv (or whatever). Don't know of the Cg equivalents.

If the colors are different for each vertex, then you can extend the vertex attributes to also transport the colors. In GLSL it would look like


varying vec4 diffuseColor;
varying vec4 specularColor;
...

and in GL the appropriate glVertexAttribPointer. Don't know of the CG equivalents.

If the colors are different from sub-mesh to sub-mesh, well, then you have the choice to go the one or the other of these ways. The former way requires more draw calls but less memory (and less bandwidth if the mesh are dynamic), while the latter way requires one 1 draw call but more memory (and more bandwidth if the mesh is dynamic).

It is, of course, also possible to make a small texture where the colors are written into individual texels. This could be made as compact as a texture where all the colors of sub-mesh 1 are in texel row 0, for sub-mesh 2 in texel row 1, ..., and the shader script picks the respective color. For this the script needs to know which row to pick for the current vertex. Hence you need to supply either a (u,v) co-ordinate or else an index (from which the script computes the (u,v) co-ordinates then) again either as uniform or varying. However, I don't know whether this is worth the effort.

Share this post


Link to post
Share on other sites
I'm sorry for my english,
i meant:
1)i have create a grouping of all the color meshes(that have a different color mesh for mesh) in an unique mesh ,that grouping all the color meshes without textures.
and i have multiplied point by point of the meshes with the corrispondent world matrix.
2)i have create a grouping of all the texturized meshes.

Now i can draw in 2 batches with 2 different shaders , one for the texture and one for the colors.
For the textures is all ok.
but for the color meshes i must send in some way all the colors for each submesh.
The problem is : HOW?
constant buffer , texture ?????
thanks for your kindness

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!