All topics about ZGameEditor goes here.
Moderator: Moderators
rrTea
Posts: 475 Joined: Sat Feb 15, 2014 9:54 am
Post
by rrTea » Sat Jan 06, 2018 8:26 am
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
VilleK
Site Admin
Posts: 2371 Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:
Post
by VilleK » Sat Jan 06, 2018 8:50 pm
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>
rrTea
Posts: 475 Joined: Sat Feb 15, 2014 9:54 am
Post
by rrTea » Sun Jan 07, 2018 3:55 am
Ah right I actually asked about the same thing on one earlier occasion
thanks Ville!!!...
rrTea
Posts: 475 Joined: Sat Feb 15, 2014 9:54 am
Post
by rrTea » Sun Jan 07, 2018 4:03 am
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>