Call component from BaseModel

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Call component from BaseModel

Post by rrTea »

I'm making some buttons with a common BaseModel. I'm trying to change their color based on certain parameters, and that color should also later be used for some other parts of the buttons, something like this:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Model2"/>
  </OnLoaded>
  <Content>
    <Material Name="Material1"/>
    <Model Name="Model1">
      <Definitions>
        <RenderSetColor Name="setCol_ButtonLabel" Color="1 1 1 1"/>
      </Definitions>
      <OnUpdate>
        <ZExpression Expression="setCol_ButtonLabel.Color = 0.5+sin(App.Time*10)*0.5;"/>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="Material1"/>
        <CallComponent Component="setCol_ButtonLabel"/>
        <RenderNet/>
      </OnRender>
    </Model>
    <Model Name="Model2" BaseModel="Model1">
      <OnRender>
        <UseMaterial Material="Material1"/>
        <CallComponent Component="setCol_ButtonLabel"/>
        <RenderNet>
          <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex.X += 2;]]>
          </RenderVertexExpression>
        </RenderNet>
      </OnRender>
    </Model>
  </Content>
</ZApplication>
How come the square on the Right doesn't blink? I'm confused :)
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Call component from BaseModel

Post by VilleK »

There are some limitations about basemodel inheritance. Try this variant that uses a Vec3 variable to hold the color and a library to set it.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Model2"/>
  </OnLoaded>
  <Content>
    <Material Name="Material1"/>
    <Model Name="Model1">
      <Definitions>
        <RenderSetColor Name="setCol_ButtonLabel" Color="1 1 1 1"/>
        <Variable Name="Variable1" Type="7"/>
        <ZLibrary>
          <Source>
<![CDATA[void setColButton() {
  setCol_ButtonLabel.Color=Variable1;
  @CallComponent(Component : setCol_ButtonLabel);
}]]>
          </Source>
        </ZLibrary>
      </Definitions>
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[setCol_ButtonLabel.Color = 0.5+sin(App.Time*10)*0.5;
Variable1 = 0.5+sin(App.Time*10)*0.5;]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="Material1"/>
        <ZExpression Expression="setColButton();"/>
        <RenderNet/>
      </OnRender>
    </Model>
    <Model Name="Model2" BaseModel="Model1">
      <OnRender>
        <UseMaterial Material="Material1"/>
        <ZExpression Expression="setColButton();"/>
        <RenderNet>
          <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex.X += 2;]]>
          </RenderVertexExpression>
        </RenderNet>
      </OnRender>
    </Model>
  </Content>
</ZApplication>
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Call component from BaseModel

Post by rrTea »

Ah right I actually asked about the same thing on one earlier occasion :oops: thanks Ville!!!... :oops: :oops:
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Call component from BaseModel

Post by rrTea »

Here's an even simpler solution based on the old discussion in case someone bumps into the same problem!... just put the @CallComponent as a ZExpression, this eliminates the need for the ZLibrary etc.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Model2"/>
  </OnLoaded>
  <Content>
    <Material Name="Material1"/>
    <Model Name="Model1">
      <Definitions>
        <RenderSetColor Name="setCol_ButtonLabel" Color="1 1 1 1"/>
        <Variable Name="Variable1" Type="7"/>
      </Definitions>
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[setCol_ButtonLabel.Color = 0.5+sin(App.Time*10)*0.5;
Variable1 = 0.5+sin(App.Time*10)*0.5;]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="Material1"/>
        <ZExpression Expression="@CallComponent(Component : setCol_ButtonLabel);"/>
        <RenderNet/>
      </OnRender>
    </Model>
    <Model Name="Model2" BaseModel="Model1">
      <OnRender>
        <UseMaterial Material="Material1"/>
        <ZExpression Expression="@CallComponent(Component : setCol_ButtonLabel);"/>
        <RenderNet>
          <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex.X += 2;]]>
          </RenderVertexExpression>
        </RenderNet>
      </OnRender>
    </Model>
  </Content>
</ZApplication>
Post Reply