Page 1 of 1

SetColor in BaseModel

Posted: Sat Dec 03, 2016 5:09 pm
by rrTea
I have a few Enemy models which use the same BaseModel. The first part of the rendering is usually done in BaseModel, but in some cases the enemies have some additional elements that I'm trying to render using the same parameters as what was used in BaseModel.

Right now I have it set up like this (the SetColor is moved from OnRender to Definitions because it has to be unique for every Enemy that uses the same BaseModel):

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ClearColor="0.502 0.502 0.7529 1" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Model1" Position="-3 0 0"/>
    <SpawnModel Model="Model2" Position="3 0 0"/>
  </OnLoaded>
  <Content>
    <Model Name="Model1">
      <Definitions>
        <RenderSetColor Name="setCol_Enemy" Color="0 1 1 1"/>
      </Definitions>
      <OnRender>
        <UseMaterial Material="Material1"/>
        <CallComponent Component="setCol_Enemy"/>
        <RenderNet/>
      </OnRender>
    </Model>
    <Model Name="Model2" BaseModel="Model1">
      <OnUpdate>
        <ZExpression Expression="setCol_Enemy.Color.R = round(frac(App.Time));"/>
      </OnUpdate>
      <OnRender>
        <RenderTransformGroup Translate="0 2 0">
          <Children>
            <UseMaterial Material="Material1"/>
            <CallComponent Component="setCol_Enemy"/>
            <RenderNet/>
          </Children>
        </RenderTransformGroup>
      </OnRender>
    </Model>
    <Material Name="Material1" Shading="1" Light="0" ZBuffer="0"/>
  </Content>
</ZApplication>
I'd expect the model on the right to be flashing in both parts, but it only flashes in the bottom part - CallComponent (in the Model2 / OnRender) obviously calls the "original" SetColor, not the model-specific. Shouldn't it call its own SetColor, not the BaseModel's?

Re: SetColor in BaseModel

Posted: Sat Dec 03, 2016 5:47 pm
by VilleK
This is a design problem in ZGE because base/child model relationships works best in scripting. So instead of the CallComponent in the Model2, try this ZExpression to script the call:

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<ZExpression Expression="@CallComponent(Component: setCol_Enemy);"/>
That seems to work here.

Re: SetColor in BaseModel

Posted: Sun Dec 04, 2016 8:27 pm
by rrTea
Yes indeed that works - thanks!

Are there any other cases where just not using a component makes things work?