Crystal Space
Welcome, Guest. Please login or register.
August 21, 2014, 11:22:50 pm

Login with username, password and session length
Search:     Advanced search
9005 Posts in 2043 Topics by 8330 Members
Latest Member: Msquartcarle03
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Defining a submesh within a genmesh factory
« previous next »
Pages: [1] Print
Author Topic: Defining a submesh within a genmesh factory  (Read 3205 times)
rvhaasen
Jr. Member
**
Posts: 62


View Profile
« on: November 21, 2007, 03:47:46 pm »

I'm changing the 3dsmax exporter to use genmeshes instead of thingmeshes, so i can use both vertex-lighting and lightmaps.

For this i want to use submeshes as part of the genmesh factories (to be able to use different materials within 1 mesh object)

From the documentation (section 4.10.8 "Genmesh Mesh Object") i conclude that such a genmesh factory could be defined as follows 

Code:
<meshfact name="t01">
  <plugin>crystalspace.mesh.loader.factory.genmesh</plugin>
    <params>
      <v x="-961.188" y="0.0" z="750.036" u="0.0" v="1.0" />
      ....
      <t v1="0" v2="1" v3="2" />
      .....
      <submesh>
         <material>....
         <mixmode>...
         <t>0</t>
         .....
      </submesh>
      ....
    </params>
  <plugin>
</meshfact>
This however doesn't work, when loading a scene with this factory i get the error:
Code:
crystalspace.syntax.badtoken: Unexpected token 't'!
In the example scenes, i can only see a submesh in "flarge". However, there the submesh is defined in a genmesh instance and not in the factory, i cannot see an example where a submesh is defined in a genmesh factory.

Does anyone knows how to do this?
Logged
bookeater2
Newbie
*
Posts: 45


View Profile Email
« Reply #1 on: November 21, 2007, 04:59:00 pm »

This is what most of them look like

Code:
      <submesh name="house.png">
        <indexbuffer components="1" type="uint" indices="yes">
          <e c0="3"/>
          <e c0="2"/>
          <e c0="1"/>
.....
        </indexbuffer>
        <material>house.png</material>
      </submesh>
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #2 on: November 22, 2007, 10:49:53 am »

What version of CS do you have? In 1.2 submeshes are *only* defined in factories. Not in meshes.

Greetings,
Logged
rvhaasen
Jr. Member
**
Posts: 62


View Profile
« Reply #3 on: November 22, 2007, 11:05:10 am »

What version of CS do you have? In 1.2 submeshes are *only* defined in factories. Not in meshes.
That sounds as it should!
Now I still use 1.01, so this is a good moment for me to make the switch....
thanks
Logged
rvhaasen
Jr. Member
**
Posts: 62


View Profile
« Reply #4 on: November 26, 2007, 01:56:24 pm »

There is a problem with specifying the texture coordinates.
From the documentation and examples i understand that the preferred way to specify texture coordinates for genmesh factories is in the "v" tags, for example:
Code:
<v x="-0.338703" y="-0.637001" z="6.718997" u="0.562855" v="0.616343" nx="-0.050111" ny="-0.094241" nz="0.994263"/>
texture coordinates however should be "tied" to triangles, and not to vertices.
In an example like in file "castle\factories\genCube" this is solved by repeating the vertex definition for each triangle:
Code:
<v x="-0.338703" y="-0.637001" z="6.718997" u="0.562855" v="0.616343" nx="-0.050111" ny="-0.094241" nz="0.994263"/>
<v x="-0.338703" y="-0.637001" z="6.734554" u="0.562855" v="-1.302350" nx="0.000000" ny="-0.816492" nz="-0.577349"/>
<v x="-0.323146" y="-0.637001" z="6.718997" u="0.552967" v="-1.302350" nx="0.000000" ny="0.000000" nz="-1.000000"/>
<t v1="2" v2="1" v3="0"/>
<v x="-0.338703" y="-0.637001" z="6.734554" u="0.552967" v="-1.302350" nx="0.000000" ny="-0.816492" nz="-0.577349"/>
<v x="-0.338703" y="-0.637001" z="6.718997" u="0.574173" v="-1.302350" nx="-0.050111" ny="-0.094241" nz="0.994263"/>
<v x="-0.354259" y="-0.637001" z="6.718997" u="0.552967" v="0.616343" nx="1.000000" ny="0.000000" nz="0.000000"/>
<t v1="5" v2="4" v3="3"/>
Although this is inefficient it works.

For the submesh however it is a problem, because you can only specify vertex indices (for the triangles). I don't know how to specify "triangle specific" texture
coordinates.

Is there a solution for this?
Logged
rvhaasen
Jr. Member
**
Posts: 62


View Profile
« Reply #5 on: November 26, 2007, 02:48:08 pm »

i just realized that it is ofcourse possible to refer to the "redundant" vertices.
This should work just as for the "non-submesh" situation, although "just as inefficient"....
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #6 on: November 27, 2007, 06:40:52 pm »

texture coordinates however should be "tied" to triangles, and not to vertices.

Many 3D modellers may work like this. Hardware doesn't. CS follows what the HW is doing.

For the submesh however it is a problem, because you can only specify vertex indices (for the triangles). I don't know how to specify "triangle specific" texture
coordinates.

Duplicate the vertex so the position is the same, but UV coords differ.
(FWIW, any 3D modelling program rather likely does the same thing internally when updating the realtime view.)
Logged
rvhaasen
Jr. Member
**
Posts: 62


View Profile
« Reply #7 on: November 28, 2007, 11:55:40 am »

i implemented it now using the indexbuffer, as suggested by bookeater2.
I followed the genmesh factory loader using walktest with the VS2005 debugger: indeed the <t> tag (as described in the CS documentation) does not exist, the only way is to specifying submeshes in genmesh factories is using the indexbuffers.
Many 3D modellers may work like this. Hardware doesn't. CS follows what the HW is doing.
i guess you are right: if it is implemented in terms of OpenGL vertexarrays (which is the most efficient way) then the vertex positions and other vertex attributes are indeed coupled.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 8.233 seconds with 17 queries.