Works only in Preview
Posted: Fri Dec 01, 2017 5:31 am
Any idea why this code only works in preview mode but not when launched (shows only black screen)?
It should look like this: (captured from the Preview)
https://streamable.com/wzxbc
Update: actually it doesn't work in freshly restarted ZGE Preview either until the RenderTarget1.ClearBeforeUse is ticked on and then ticked off again.
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ClearColor="0.502 0.502 1 1" FileVersion="2">
<OnLoaded>
<Repeat Count="20">
<OnIteration>
<SpawnModel Model="Model1"/>
</OnIteration>
</Repeat>
</OnLoaded>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[float t;
t = App.Time;
setCol_Tone.Color.R = 0.3 + noise2(t, sin(t));
setCol_Tone.Color.G = 0.7 - noise2(sin(t), cos(t));
setCol_Tone.Color.B = 0.5 + noise2(cos(t), sin(t+0.25));]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnBeginRenderPass>
<SetRenderTarget RenderTarget="RenderTarget1"/>
<UseMaterial Material="mat_Transparent"/>
<RenderSetColor Name="setCol_Tone" Color="0.2259 0.7823 0.599 0.01"/>
<RenderTransformGroup Scale="6 4 1">
<Children>
<RenderMesh Mesh="Mesh1"/>
</Children>
</RenderTransformGroup>
</OnBeginRenderPass>
<OnRender>
<SetRenderTarget/>
<UseMaterial Material="mat_RT"/>
<RenderTransformGroup Scale="4 4 1">
<Children>
<RenderMesh Mesh="Mesh1"/>
</Children>
</RenderTransformGroup>
</OnRender>
<Content>
<RenderTarget Name="RenderTarget1" CustomWidth="160" CustomHeight="120" ClearBeforeUse="0" Filter="1"/>
<Material Name="mat_RT" Comment="Rendertarget" Light="0">
<Textures>
<MaterialTexture RenderTarget="RenderTarget1" TextureWrapMode="2" TexCoords="1"/>
</Textures>
</Material>
<Material Name="mat_Base" Comment="base" Shading="1" Light="0"/>
<Material Name="mat_Transparent" Comment="Used for masking" Shading="1" Light="0" Blend="1"/>
<Material Name="mat_Point" Shading="3" Color="0 1 1 1" Light="0"/>
<Mesh Name="Mesh1">
<Producers>
<MeshBox Grid2DOnly="255"/>
</Producers>
</Mesh>
<Model Name="Model1" Scale="0.5 0.5 0.5" Category="1">
<OnSpawn>
<ZExpression>
<Expression>
<![CDATA[CurrentModel.Rotation.Z = CurrentModel.Personality;
CurrentModel.Position.X = sin(CurrentModel.Personality*Pi*2);
CurrentModel.Position.Y = cos(CurrentModel.Personality*Pi*2);]]>
</Expression>
</ZExpression>
</OnSpawn>
<OnUpdate>
<SteeringController Mass="0.5" MaxSpeed="0.5" MaxForce="5" AdjustHeading="255">
<Behaviours>
<SteeringBehaviour Kind="2"/>
</Behaviours>
</SteeringController>
<Condition>
<Expression>
<![CDATA[return(
abs(CurrentModel.Position.X) > 4f*8/6
||abs(CurrentModel.Position.Y) > 4f*1
);]]>
</Expression>
<OnTrue>
<ZExpression Expression="CurrentModel.Position = 0;"/>
</OnTrue>
</Condition>
<ZExpression>
<Expression>
<![CDATA[float t,p;
t = App.Time*0.1;
p = CurrentModel.Personality;
CurrentModel.Scale = 0.4 + noise2(t*p, sin(t)+p);]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnRender>
<UseMaterial Material="mat_Point"/>
<RenderMesh Mesh="Mesh1"/>
</OnRender>
</Model>
<Mesh Name="Mesh2">
<Producers>
<MeshBox/>
</Producers>
</Mesh>
</Content>
</ZApplication>
It should look like this: (captured from the Preview)
https://streamable.com/wzxbc
Update: actually it doesn't work in freshly restarted ZGE Preview either until the RenderTarget1.ClearBeforeUse is ticked on and then ticked off again.