Page 1 of 1

base model usage question

Posted: Mon Mar 09, 2020 6:02 am
by sky_haihai
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

Re: base model usage question

Posted: Mon Mar 09, 2020 7:46 am
by rrTea
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.

Re: base model usage question

Posted: Mon Mar 09, 2020 4:35 pm
by sky_haihai
Thank you !! problem solved