commands for mesh manipulation

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: commands for mesh manipulation

Post by Kjell »

Hi Ats,
Ats wrote: Thu Nov 22, 2018 11:42 amI'm having problems trying to display different meshes variations using a single model.
I'm afraid that's not enough information to give you a proper suggestion ..
Ats wrote: Thu Nov 22, 2018 11:42 amDo I have to store the variation values inside the model and use refreshComponent on the mesh for each frame? Wouldn't that slow down everything?
That sounds like a bad idea yes.

K
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: commands for mesh manipulation

Post by Ats »

Hahaha
Here, I made a quick mockup. I'm trying to obtain 4 different rock meshes on the 4 spawned models. But since the mesh is called at each frame to be displayed, I don't get how to do that...

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[model m;
for(int B=0; B<4; B++)
{
  m = createModel(RockModel);
  m.Position.X = -6 + 4*B;
  m.Position.Y = -2;
}]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Mesh Name="RockMesh">
      <Producers>
        <MeshBox XCount="4" YCount="4" Grid2DOnly="255"/>
        <MeshExpression Name="RockMeshExpression">
          <Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
if (V.X == -1 || V.X == 1 || V.Y == -1 || V.Y == 1) V.Z = 0;
else V.Z += cos(V.X*V.Y)*1.5+rnd();
V.X += rnd()*V.X;
V.Y += rnd()*V.Y;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Rotation="-0.25 0 0"/>
      </Producers>
    </Mesh>
    <Model Name="RockModel">
      <OnSpawn>
        <RefreshContent Component="RockMeshExpression"/>
      </OnSpawn>
      <OnRender>
        <RenderMesh Mesh="RockMesh"/>
      </OnRender>
    </Model>
  </Content>
</ZApplication>
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: commands for mesh manipulation

Post by Kjell »

Hi Ats,
Ats wrote: Thu Nov 22, 2018 5:11 pmHere, I made a quick mockup. I'm trying to obtain 4 different rock meshes on the 4 spawned models. But since the mesh is called at each frame to be displayed, I don't get how to do that...
Ah, that's easy .. simply move RockMesh into RockModel.Definitions and remove the RefreshContent component. So like this ..

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[model m;
for(int B=0; B<4; B++)
{
  m = createModel(RockModel);
  m.Position.X = -6 + 4*B;
  m.Position.Y = -2;
}]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Model Name="RockModel">
      <Definitions>
        <Mesh Name="RockMesh">
          <Producers>
            <MeshBox XCount="4" YCount="4" Grid2DOnly="255"/>
            <MeshExpression Name="RockMeshExpression">
              <Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
if (V.X == -1 || V.X == 1 || V.Y == -1 || V.Y == 1) V.Z = 0;
else V.Z += cos(V.X*V.Y)*1.5+rnd();
V.X += rnd()*V.X;
V.Y += rnd()*V.Y;]]>
              </Expression>
            </MeshExpression>
            <MeshTransform Rotation="-0.25 0 0"/>
          </Producers>
        </Mesh>
      </Definitions>
      <OnRender>
        <RenderMesh Mesh="RockMesh"/>
      </OnRender>
    </Model>
  </Content>
</ZApplication>
K
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: commands for mesh manipulation

Post by Ats »

I knew it was simple... I got carried away with the RefreshContent component :lol:
That opens a new world of perspectives for my game. Thanks !
Post Reply