commands for mesh manipulation

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

commands for mesh manipulation

Post by zakkwylde »

does anybody know all the commands to manipulate meshes? i am trying to produce inbuilt shapes within zge instead of importing 3ds shapes. for one i am trying to create a mesh thats undulating, to create a terrain. nex5, i am trying to create other shapes like a flat circle or triangle. these can be done by manipulating individual vertices within the mesh but i cant seem to find any help on this. if someone could provide me a list of commands i can use and even examples, will b real grateful. thanks!
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: commands for mesh manipulation

Post by Rado1 »

All mesh manipulation components are described in ZGE help (press F1) - sub-pages of Components / Mesh page. To manipulate nodes problematically, you'll need to use MeshExpression. Some examples you'll find in "Add from library.../ Meshes" context menu available in the in Project tree's nodes.
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Re: commands for mesh manipulation

Post by zakkwylde »

thanks for the reply. saw the help desk but i think fundamentally i need to clarify how to target specific vertex. for example if i want the vertex at x=2,z=3 to move on y axis to 5.how would u type this out?
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: commands for mesh manipulation

Post by Rado1 »

Usually, you do not address particular points, but write a function. Like this for Pillow mesh from built-in library:

Code: Select all

float V2 = v.X*PI;
float U = v.Y*PI;

v.X = cos(U);
v.Y = cos(V2);
v.Z = 0-((sin(U)*sin(V2))/Pi*2);
Starting with 2D MeshBox component you then apply MeshExpression with the aforementioned code.

But of course, you can also target specific vertex, if you know its position:

Code: Select all

if(V.X == 2 && V.Z == 3) V.Y = 5;
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: commands for mesh manipulation

Post by Kjell »

Hi zakkwylde,

Here's a flat circle ( CircleGrid.XCount controls the number of segments ) ..

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="CircleMesh">
  <Producers>
    <MeshBox Name="CircleGrid" XCount="2" Grid2DOnly="255"/>
    <MeshExpression>
      <Expression>
<![CDATA[float s, o, a;

s = PI*(0.5-0.5/(CircleGrid.XCount+2));
o = CircleGrid.XCount & 1 ? 0.0 : PI*0.5/(CircleGrid.XCount+2);

if(V.Y > 0)
{
  a = V.X*s+o;

  V.X =   sin(a);
  V.Y =   cos(a);
}
else
{
  a = V.X*s-o;

  V.X =   sin(a);
  V.Y = 0-cos(a);
}]]>
      </Expression>
    </MeshExpression>
  </Producers>
</Mesh>
Needlessly complicated ( having to manipulate a 2D grid ) compared to generating the vertex & index data directly, but .. しょうがない。

K
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Re: commands for mesh manipulation

Post by zakkwylde »

guys,
many thanks for the replies. i tried something simple first (kjell, hope u dont mind, baby steps first though drawing a circle is on my to do list). but after i keyed in rado's example i had a few errors:
1. i had to type in this.vertex.x or y or z, i cant use v.x etc, zge simply wont let me. is this a zge version issue?
2. even when i used the long form in 1., i had one instance where the mesh disappeared or became invisible in the preview window. another instance, the mesh remained flat, no hill no bump, flat as an airfield. if rado could do a zgeproj file with that same coding line, i would like to try that out. but on my end its not coming out at all.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: commands for mesh manipulation

Post by Kjell »

Hi zakkwylde,
zakkwylde wrote:i had to type in this.vertex.x or y or z, i cant use v.x etc, zge simply wont let me. is this a zge version issue?
Which version of ZGameEditor are you using? Long ago you had to use "this." in MeshExpressions .. but it was never "this.Vertex" ( unless you're writing a RenderNet expression ).
zakkwylde wrote:i had one instance where the mesh disappeared or became invisible in the preview window.
If your expression ends up putting vertices in such a way that the mesh doesn't have any volume ( a line for example ), it won't be visible anymore.
zakkwylde wrote:another instance, the mesh remained flat, no hill no bump, flat as an airfield.
Entirely possible :)

K
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: commands for mesh manipulation

Post by VilleK »

It is inconvenient to use MeshExpression for mesh generation.

Maybe we should rename existing MeshExpression component to MeshModifyExpression (or MeshFilterExpression) to make it clear that it modifies an already existing mesh. And then add a new MeshGenerateExpression for generating a mesh. Though I'm not sure how such a component would be designed (how should the expression actually generate vertices, tex coords, normals etc). I'm open for ideas and suggestions :)
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Re: commands for mesh manipulation

Post by zakkwylde »

Guys,
I think i did not clarify enough at the start. But your helpful suggestions are beginning to shed some light.
I used Rendernet. should i be using Mesh Expression instead? Maybe thats why these were not working.
What is the lowest footprint way then?
I thought with rendernet, i could simply type in the vertex lines and thats it, that rendernet mesh will be the one.
But with mesh and mesh expression, thats 2 items, it will use up a little more resource to carry out those codes.
So do clarify, the commands you have indicated so far are for MeshExpression or Rendernet?
Are they not interchangeable?
If so, are there any Rendernet-friendly expressions i can use?
Thanks guys, lets keep it coming!
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: commands for mesh manipulation

Post by Kjell »

Hi guys,
zakkwylde wrote:What is the lowest footprint way then?
There's no major difference, the most important thing you need to know is that RenderNet automatically recreates the mesh each frame .. so unless you need to render a net / grid that needs to be updated each frame, use the Mesh component instead.
zakkwylde wrote:Are they not interchangeable?
Yes and no .. they use the exact same syntax, but the vertex attributes have different names ( no idea why ). In a RenderNet expression they are called Vertex / TexCoord / Color while in a MeshExpression they are called V / TexCoord / C / N ( for Normal ).
VilleK wrote:Maybe we should rename existing MeshExpression component to MeshModifyExpression (or MeshFilterExpression) to make it clear that it modifies an already existing mesh. And then add a new MeshGenerateExpression for generating a mesh.
I don't think there's much wrong with the current approach, it's just that some primitives are missing.

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

Re: commands for mesh manipulation

Post by Ats »

Hi, I'm discovering MeshExpression in order to create random rocks and stuff.
So I'm moving the vertexes of a sphere in order to get something random but a bit convincing. The problem is that I don't know how to make the last vertexes to be on the same position as the firts, as they don't seem to be attached. Is that possible?

Here's a snippet with the problem visible:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <Content>
    <Mesh Name="RockMesh">
      <Producers>
        <MeshSphere ZSamples="5" RadialSamples="5"/>
        <MeshExpression>
          <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)
V.Y = clamp(V.Y+rnd()*.4, 0, V.Y + 1);
V.X += rnd()*.5-rnd()*.5;
V.Z += rnd()*.5-rnd()*.5;]]>
          </Expression>
        </MeshExpression>
      </Producers>
    </Mesh>
  </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: Wed Nov 21, 2018 8:20 amSo I'm moving the vertexes of a sphere in order to get something random but a bit convincing. The problem is that I don't know how to make the last vertexes to be on the same position as the firts, as they don't seem to be attached.
Correct, MeshSphere isn't closed off properly ( even though it should ). There are some ways to work around this, but you can't use AutoNormals in any case.

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

Re: commands for mesh manipulation

Post by Ats »

I'm not sure if I need vertexes normals as my game only uses flat shading. But since there's no easy way to close a sphere, I've started again from a flat box. I believe my rock is taking shape, maybe :

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <Content>
    <Mesh Name="RockMesh">
      <Producers>
        <MeshBox XCount="4" YCount="4" Grid2DOnly="255"/>
        <MeshExpression>
          <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>
  </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: Wed Nov 21, 2018 7:25 pmI'm not sure if I need vertexes normals as my game only uses flat shading.
Flat shading doesn't determine whether or not you need normals. It's about whether or not you're using lights.
Ats wrote: Wed Nov 21, 2018 7:25 pmBut since there's no easy way to close a sphere, I've started again from a flat box.
Starting from a 2D grid can make things a bit easier yes :)

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

Re: commands for mesh manipulation

Post by Ats »

Cool :)

I'm having problems trying to display different meshes variations using a single model. Do 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?
Post Reply