Crystal Space
Welcome, Guest. Please login or register.
December 19, 2014, 01:27:58 pm

Login with username, password and session length
Search:     Advanced search
9032 Posts in 2046 Topics by 9291 Members
Latest Member: Echkime
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  loading sectors and objects seperately
« previous next »
Pages: [1] Print
Author Topic: loading sectors and objects seperately  (Read 3530 times)
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« on: November 09, 2007, 02:27:11 am »

Hi,

I have a simple Crystal Space C++ application which loads a map from an XML World file with one sector "room" which is basically just terrain.
Is there some way to load objects to the same sector from another file?

So for instance, in the first XML file we have the sector "room" which contains the entire terrain but nothing else.
Lets we want to place 10 different objects on this terrain.
The usual way would be to define all the factories textures, materials and genmesh objects within the first World file.
But is it possible to have the factories, textures, materials and meshobject definitions in a "second" file and load them into the same sector "room" which was defined in the first file?

If yes, could someone please provide some hints or link to some code which shows how to do this?

Many thanks in advance.

/regards
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: November 09, 2007, 06:20:02 am »

Yes that's very easy. Just have the second file contain the sector again. If two sectors are loaded but they have the same name then the sectors are actually merged and you will get only one sector with the combination of objects.

Greetings,
Logged
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« Reply #2 on: November 09, 2007, 08:44:12 am »

Thanks very much, it is interesting indeed.

However, now I seem to be having a problem with lighting.
It does not calculate lighting for the second file I load and keeps informing to use -relight but I don't have such a switch in my app.
Basically, when I do   engine->Prepare (); should it not recalculate all lighting itself?

In the second XML file I am using ambient light as follows:

  <settings>
    <clearzbuf>yes</clearzbuf>
    <ambient red="0.5" green="0.5" blue="0.5" />
    <lightmapcellsize>16</lightmapcellsize>
  </settings>

Should this work or am I doing something wrong?

Many thanks again,

/regards
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: November 09, 2007, 09:00:59 am »

You can always do -relight on the commandline. Every CS app has that switch because it is handled by CS. But anyway, in your case you can just call engine->SetLightingCacheMode(0) right before engine->Prepare(). That way it will be recalculated every time the app starts.

Greetings,
Logged
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« Reply #4 on: November 09, 2007, 10:05:52 am »

ok, I tried in both ways and now its recalculating lights but I still see absolutely nothing other than flicker.

Here is my entire second world file (loaded after the first one).

<world>

  <textures>
    <texture name="Yellobrk.JPG"> <file>Yellobrk.JPG</file></texture>
  </textures>
  <materials>
    <material name="Yellobrk.JPG"> <texture>Yellobrk.JPG</texture></material>
  </materials>

  <sector name="room">
    <cullerp>crystalspace.culling.dynavis</cullerp>
    <meshobj name="raekoda">
      <plugin>thing</plugin>
      <priority>object</priority>
      <zuse />
      <params>
      <v x="-13.0215" y="0.0" z="-15.0" />
      <v x="1.97853" y="0.0" z="-15.0" />
      <v x="-13.0215" y="0.0" z="15.0" />
      <v x="1.97853" y="0.0" z="15.0" />
      <v x="-13.0215" y="20.0" z="-15.0" />
      <v x="1.97853" y="20.0" z="-15.0" />
      <v x="-13.0215" y="20.0" z="15.0" />
      <v x="1.97853" y="20.0" z="15.0" />

      <material>Yellobrk.JPG</material>
      <p name="raekoda_1">      <v>3</v><v>2</v><v>0</v><v>1</v>
      <texmap><uv idx="0" u="0.0" v="0.0" /><uv idx="1" u="1.0" v="0.0" /><uv idx="2" u="1.0" v="1.0" /></texmap></p>
      <p name="raekoda_3">      <v>7</v><v>5</v><v>4</v><v>6</v>
      <texmap><uv idx="0" u="1.0" v="0.0" /><uv idx="1" u="1.0" v="1.0" /><uv idx="2" u="0.0" v="1.0" /></texmap></p>
      <p name="raekoda_5">      <v>5</v><v>1</v><v>0</v><v>4</v>
      <texmap><uv idx="0" u="1.0" v="0.0" /><uv idx="1" u="1.0" v="1.0" /><uv idx="2" u="0.0" v="1.0" /></texmap></p>
      <p name="raekoda_7">      <v>7</v><v>3</v><v>1</v><v>5</v>
      <texmap><uv idx="0" u="1.0" v="0.0" /><uv idx="1" u="1.0" v="1.0" /><uv idx="2" u="0.0" v="1.0" /></texmap></p>
      <p name="raekoda_9">      <v>6</v><v>2</v><v>3</v><v>7</v>
      <texmap><uv idx="0" u="1.0" v="0.0" /><uv idx="1" u="1.0" v="1.0" /><uv idx="2" u="0.0" v="1.0" /></texmap></p>
      <p name="raekoda_11">      <v>4</v><v>0</v><v>2</v><v>6</v>
      <texmap><uv idx="0" u="1.0" v="0.0" /><uv idx="1" u="1.0" v="1.0" /><uv idx="2" u="0.0" v="1.0" /></texmap></p>
      </params>
    </meshobj>

    <light name="Omni01room">
    <attenuation>none</attenuation>
      <center x="1.8824" y="30.7916" z="-25.372" />
      <radius>200.0</radius>
      <color red="1.0" green="1.0" blue="1.0" />
    </light>
  </sector>

</world>

The first file only has a terrain mesh object in the sector 'room' plus 'sun' light, and by itself works fine.

any ideas why this is not working?

/regards
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #5 on: November 09, 2007, 10:08:47 am »

Can you also show the other world file?

Greetings,
Logged
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« Reply #6 on: November 09, 2007, 10:15:12 am »

Sure, here it comes:

<?xml version="1.0" encoding="utf-8" ?>
<world>

<!--*** initialization part ***-->
<!-- plugin section -->
  <plugins>
    <plugin name="thingFact">crystalspace.mesh.loader.factory.thing</plugin>
    <plugin name="thing">crystalspace.mesh.loader.thing</plugin>
    <plugin name="genmeshFactory">crystalspace.mesh.loader.factory.genmesh</plugin>
    <plugin name="genmesh">crystalspace.mesh.loader.genmesh</plugin>
    <plugin name="terrainFact">crystalspace.mesh.loader.factory.terrain</plugin>
    <plugin name="terrain">crystalspace.mesh.loader.terrain</plugin>
  </plugins>

<!-- texture specification section -->
  <textures>
    <texture name="grass.png">
      <file>/lev/terrain/grass.png</file>
    </texture>
    <texture name="grassDOT3.png">
      <file>/lev/terrain/grassDOT3.png</file>
      <class>normalmap</class>
    </texture>
    <texture name="basemap">
      <file>/lev/terrain/materialmap_base.png</file>
    </texture>
    <texture name="base_normalmap">
      <file>/lev/terrain/normalmap.png</file>
      <class>normalmap</class>
    </texture>
  </textures>


<!-- shader section -->

  <shaders>
    <shader><file>/shader/sky_scattering.xml</file></shader>
    <shader><file>/shader/splatting_base.xml</file></shader>
    <shader><file>/shader/splatting_scattering_base.xml</file></shader>
    <shader><file>/shader/splatting_bump.xml</file></shader>
    <shader><file>/shader/splatting_scattering.xml</file></shader>
  </shaders>


<!-- material specification section -->
  <materials>
    <material name="ScatterSky">
      <color red="0" green="0" blue="0" />

      <shadervar type='vector3' name="sky base color">0.0,0.1,0.2</shadervar>
      <shadervar type='vector3' name="sky sun-glow color">0.9,0.3,0.01</shadervar>
      <shadervar type='float' name="sky sun size">0.004</shadervar>

      <shader type="ambient">sky_scattering</shader>
    </material>
   
    <material name="Base">
      <texture>basemap</texture>
      <shadervar name="tex normal" type="texture">base_normalmap</shadervar>
      <shader type="ambient">splatting_scattering_base</shader>
    </material>
   
    <material name="Grass">
      <texture>grass.png</texture>
      <shadervar name="tex normal" type="texture">grassDOT3.png</shadervar>
      <shadervar name="texture scale" type="vector2">16,16</shadervar>
      <!-- <shader type="diffuse">splatting_bump</shader> -->
      <shader type="terrain splat">splatting_scattering</shader>
    </material>
  </materials>


<!-- sounds section -->

<!-- variable section -->

<!-- add-ons section -->

  <addon>
     <plugin>crystalspace.renderloop.loop.loader</plugin>
   <paramsfile>/shader/std_rloop_terrain.xml</paramsfile>
  </addon>


<!-- settings section -->

  <settings>
    <clearzbuf>yes</clearzbuf>
    <lightmapcellsize>16</lightmapcellsize>
    <renderloop>std_rloop_terrain</renderloop>
  </settings>


<!-- start locations section -->

  <start>
    <sector>room</sector>
    <position x="100" y="30" z="0" />
    <forward x="0" y="0" z="5" />
    <!-- <up x="0" y="1" z="0" /> -->
  </start>


<!-- library section -->

<!-- keys section -->

<!--*** world elements part ***-->

<!-- mesh factories -->

  <meshfact name="skydome">
    <plugin>genmeshFactory</plugin>
    <params>
      <sphere rimvertices="64" reversed="true">
   <radius x="500000" y="500000" z="500000" />
      </sphere>
    </params>
  </meshfact>

  <addon>
    <plugin>crystalspace.terraformer.simple.loader</plugin>
    <params>
      <name>simple</name>
      <heightmap>/lev/terrain/Tallinn1024x1024.png</heightmap>
      <scale x="8192" y="69" z="8192" />
      <materialmap image="/lev/terrain/materialmap.png" />
    </params>
  </addon>

  <meshfact name="TerrainFact">
    <plugin>terrainFact</plugin>
    <params>
      <plugin>crystalspace.mesh.object.terrain.bruteblock</plugin>
      <terraformer>simple</terraformer>
      <sampleregion>
        <min x="-1024" y="-1024" />
        <max x="8192" y="8192" />                   
      </sampleregion>
    </params>
  </meshfact>

<!--*** world definition part ***-->

<!-- sectors -->

  <sector name="room">
    <light name="sun">
      <center x="500000" y="866030" z="0" />
      <radius>0</radius>
      <color red="0.85903" green="0.80995" blue="0.70420" />
      <influenceradius>10000000</influenceradius>
      <attenuation>realistic</attenuation>
    </light>

    <meshobj name="sky">
      <plugin>genmesh</plugin>
      <params>
        <factory>skydome</factory>
        <material>ScatterSky</material>
        <color red="0" green="0" blue="0" />
      </params>
      <zfill />
      <priority>sky</priority>
      <camera />
      <polymesh> <colldet/> </polymesh>
    </meshobj>

    <meshobj name="Terrain">
      <plugin>terrain</plugin>
      <params>
        <factory>TerrainFact</factory>
        <material>Base</material>
   <materialpalette>
     <material>Grass</material>
   </materialpalette>
        <lodvalue name="splatting distance">200</lodvalue>
        <lodvalue name="block resolution">16</lodvalue>
        <lodvalue name="block split distance">8</lodvalue>
        <lodvalue name="minimum block size">32</lodvalue>
      </params>
      <move>
        <v x="0" y="0" z="0" />
      </move>
    </meshobj>

  </sector>

<!-- collections -->

<!--*** actions part ***-->

<!-- sequence section -->
<!-- trigger section -->

</world>


/regards
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #7 on: November 09, 2007, 10:54:59 am »

First problem. First you specify dynavis culler in the second world while you don't specify one in the first so that will default to frustvis. Use the same culler for both (I recommend frustvis).

Secondly can show me the code that you use to load both maps?

Greetings,
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #8 on: November 09, 2007, 11:13:29 am »

Ok, your problem is that you're using LoadMapFile() with the wrong parameters the second time. By default LoadMapFile() will clear everything in the engine. So when you load your second map the first one will be unloaded. Check the api of LoadMapFile() for parameters on how to prevent that.

Greetings,
Logged
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« Reply #9 on: November 09, 2007, 11:30:23 am »

Thank you very much. Loding with LoadMapFile ("raekoda", false) solved it.

So the application now runs, but the strage thing is that the box still does not appear in the level.
I have the start position set at 0,0,0 and the box should be somewhere around here but its nowhere to be found Smiley

I'll look more into it myself but if you got any idea I'd appreciate.

/regards
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #10 on: November 09, 2007, 11:31:42 am »

That's because your second map uses a thing plugin with materials that don't work on the renderloop that you use in the first map. You need to set correct materials with shaders that are compatible with the terrain renderloop.


Greetings,
Logged
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« Reply #11 on: November 09, 2007, 12:17:18 pm »

yes, this is where I really have a problem that I do not understand CS shaders well.
I have read everything about shaders what is in the manual but still unable to understand how exactly to use them or write own shaders.

Is there some place other than the manual where shaders are explained more?
For instance, there are a huge number of shaders in the /shader CS folder and I would really like to know what each one of these shaders does and how to use it.

Is there any place where such info can be found?

another question I have is regarding the efficiency of shaders. My application needs to be **very** efficient memory wise and processing wise, even if that means not having some cool graphic effects. so I need to know how the use of shaders compare against using just simple textures and materials? which way is more efficient memory wise and processing wise?

/regards
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #12 on: November 09, 2007, 12:32:27 pm »

Maybe you should consider using the terrain in terrainf instead. You based your terrain example on terrain but data/terrainf/world is more optimal and more compatible with objects like you use in the second world file. It is basically a matter of selecting different renderloop and shaders for the terrain.

Greetings,
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 6.364 seconds with 15 queries.