About Store Forum Documentation Contact



Post Reply 
Issue with the Heightmap code sample in Tutorial
Author Message
aceio76 Offline
Source Licensee

Post: #1
Issue with the Heightmap code sample in Tutorial
The lines in error are:
Quote: mesh.simplify (1, 0.05, 1, 0.03, 0.08, PI, true, 0, SIMPLIFY_PLANES); // simplify
(This post was last modified: 05-31-2017 08:43 PM by aceio76.)
05-31-2017 08:43 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Source Licensee

Post: #2
RE: Issue with the Heightmap code sample in Tutorial
mesh.simplify(1, 0.5, 1, 0.3, 0.08, PI, true, SIMPLIFY_PLANES, EPS)
alternatively if you want to keep original mesh
mesh.simplify(1, 0.5, 1, 0.3, 0.08, PI, true, SIMPLIFY_PLANES, EPS, &secondmesh);

although it seems the order of the variables has been changed as well
(This post was last modified: 05-31-2017 09:47 PM by Zervox.)
05-31-2017 09:44 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Issue with the Heightmap code sample in Tutorial
Thank you very much, fix will be included in the next release, here's the correct code:
Code:
/******************************************************************************/
Heightmap heightmap;
Mesh      mesh;
PhysPart  phys;
Actor     actor;
UID       grass_id=UID(3015359194, 1248539670, 3822661250, 1853126960),
           path_id=UID(2519161163, 1078307672, 184317862, 2816697732);
/******************************************************************************/
void Build(Heightmap &heightmap, Mesh &mesh, PhysPart &phys, Actor &actor) // build 'mesh', 'phys' and 'actor' from 'heightmap'
{
   actor.del();

   // build mesh
   heightmap.build(mesh, 0, 6, HM_AO|HM_SOFT, null, null, null, null, null, null, null, null);

   // adjust mesh scale and position
   flt scale=32;
   Vec pos(0, 0, 0);
   mesh.scaleMoveBase(scale, pos);

   // simplify the mesh
   mesh.simplify (1, 0.05, 1, 0.02, 0.02, PI, true, SIMPLIFY_PLANES); // simplify
   mesh.setRender(); // set rendering version from software version

   // create physical body
   MeshBase base; base.createPhys(mesh); base.simplify(1, 0.05, 1, 1, 1, PI, true, SIMPLIFY_PLANES); // create a 1 MeshBase from all MeshParts in mesh and simplify it again
   phys .createMesh(base); // create physical body from that MeshBase
   actor.create    (phys); // create actor         from physical body

   mesh.delBase(); // mesh software version is no longer needed
}
/******************************************************************************/
void InitPre()
{
   EE_INIT();
   Ms.hide();
   Ms.clip(null, 1);

   Cam.dist=24;
   Cam.pitch=-1.3;
   Cam.at.set(16, 0, 16);

   Sky.atmospheric();
}
/******************************************************************************/
bool Init()
{
   Physics.create(EE_PHYSX_DLL_PATH);

   heightmap.create(32, 0, grass_id, false, null, null, null, null, null, null, null, null); // create heightmap

   Build(heightmap, mesh, phys, actor); // build mesh phys actor from heightmap

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Cam.transformByMouse(0.01, 50, CAMH_ZOOM|(Ms.b(1) ? CAMH_MOVE : CAMH_ROT));

   // adjust the heightmap
   {
      // set material
      heightmap.setMaterial(Random(32), Random(32), Random(2) ? grass_id : path_id, null, null, VecB(255, 0, 0));

      // set height
      Vec2 pos; SinCos(pos.y, pos.x, Time.time()); pos=pos*8+16;
      REPD(x, heightmap.resolution())
      REPD(y, heightmap.resolution())
      {
         flt d=Dist(Vec2(x,y), pos);
         heightmap.height(x, y, BlendSmoothCube(d/10)*0.1);
      }
   }

   // rebuild after making changes
   Build(heightmap, mesh, phys, actor);

   return true;
}
/******************************************************************************/
void Render()
{
   switch(Renderer())
   {
      case RM_PREPARE:
      {
         mesh.draw(MatrixIdentity); // draw mesh

         LightDir(Cam.matrix.z, 1-D.ambientColor()).add();
      }break;
   }
}
/******************************************************************************/
void Draw()
{
   Renderer.wire=Kb.b(KB_TILDE);
   Renderer(Render);

   if(Ms.b(0))
   {
      if(Renderer.rebuildDepthNeededForDebugDrawing())Renderer.rebuildDepth();
      Physics.draw();
   }
  
   D.text(0, 0.9, "Press LMB to draw Physics");
   D.text(0, 0.8, "Press Tilde for Wireframe view");
   D.text(0, 0.7, S+Time.fps());
}
/******************************************************************************/
06-01-2017 01:05 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Source Licensee

Post: #4
RE: Issue with the Heightmap code sample in Tutorial
Thanks, Greg. It's an easy fix, just wanted to point it out.
06-01-2017 02:35 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply