base model usage question

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
sky_haihai
Posts: 4
Joined: Sat Mar 07, 2020 12:36 am

base model usage question

Post by sky_haihai » Mon Mar 09, 2020 6:02 am

does anyone have an example of the usage of baseModel?
the problem i have is: say there is a model named "base" and two other models named "player" and "enemy" which both use "base" as their base models. If I want to change the player's renderMesh component which is located inside "base" when pressing a key, what should I do? I tried changing the value of the Mesh by calling MyRender.Mesh=MyMesh, but soon realized when MyRender is outside of the player model, changing its value doesn't affect the one in the current "clone", as the ZGE help says. However, this doesn't match my expectation, because when i test this for variables they change separately between "player" and "enemy" model...why component value can't while variables can?
Or maybe basemodel is useful for variables only?
can anyone please explain? thanks a lot
Last edited by sky_haihai on Mon Mar 09, 2020 4:30 pm, edited 1 time in total.

User avatar
rrTea
Posts: 406
Joined: Sat Feb 15, 2014 9:54 am
Contact:

Re: base model usage question

Post by rrTea » Mon Mar 09, 2020 7:46 am

It depends on the context, but just as an illustration here is a simple way of setting the mesh you want to show in the base model, basically move the RenderMesh component to Definitions…

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Enemy1" Position="-4 0 0"/>
    <SpawnModel Model="Enemy2" Position="4 0 0"/>
  </OnLoaded>
  <Content>
    <Model Name="base_Enemy">
      <Definitions>
        <RenderMesh Name="rMesh_Body"/>
      </Definitions>
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[if ( frac(App.Time + CurrentModel.Personality)<0.5 )
   {
   rMesh_Body.Mesh = Mesh1;
   }
   else
   {
   rMesh_Body.Mesh = Mesh2;
   }]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="Material1"/>
        <CallComponent Component="rMesh_Body"/>
      </OnRender>
    </Model>
    <Model Name="Enemy1" BaseModel="base_Enemy" RotationVelocity="0 0 0.1"/>
    <Model Name="Enemy2" BaseModel="base_Enemy" RotationVelocity="0 0 -0.1"/>
    <Material Name="Material1"/>
    <Mesh Name="Mesh1">
      <Producers>
        <MeshBox Grid2DOnly="255"/>
      </Producers>
    </Mesh>
    <Mesh Name="Mesh2">
      <Producers>
        <MeshBox XCount="10" YCount="10" Grid2DOnly="255"/>
        <MeshNoise NoiseSpeed="1 1 1" NoiseScale="1 1 1"/>
      </Producers>
    </Mesh>
  </Content>
</ZApplication>
You can also do it with States too (in the Base model). I'm a bit confused by the idea of using the same base for Player and Enemy models, but I guess it depends on your project.

sky_haihai
Posts: 4
Joined: Sat Mar 07, 2020 12:36 am

Re: base model usage question

Post by sky_haihai » Mon Mar 09, 2020 4:35 pm

Thank you !! problem solved

Post Reply