Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - davec64

Pages: 1 [2] 3
16
Support / Re: Adding / modifying textures on a plane primitive on the fly.
« on: December 11, 2013, 12:46:49 pm »
Spoke to soon
I am having an issue with the textures. They are not tiling correctly. If I use a tile 32*32 the top left I set to 0,0 then to get set the texture from my 256*256. I use 1/256 * 32 0 depth tile which should give me the far edge of the first of my depth texture  tiles ??.
I am getting part of the next tile or some thing is alias ing the edge of the texture when it is displayed.
I think this may be something that I have not done. I have played around with the far edge but it always does the same thing unless it is a solid color and it covers at least 2 extra pixels around the 1st tile texture.
It basically looks like there are extremely thin lines or a shadow on the edge of each polygon.
Not the hypotenuse. Just the edges.
Dave

17
Support / Re: Adding / modifying textures on a plane primitive on the fly.
« on: November 29, 2013, 06:42:21 am »
All Done and it works really well.
 I have 64 32*32 sub textures in a single 256*256 texture.
selecting the depth sets up the correct texture based on depth.
I have put the code up as an idiots guide of how to change a texture on an object that has already been built.
 
You must do this first before you compile. (retexture method from advanced example modified)

Code: [Select]
PolygonManager pm = obj.getPolygonManager();
    int t2Id = TextureManager.getInstance().getTextureID(t2);
    int end = pm.getMaxPolygonID();
    Logger.log(end + "num of polygons");
    int t1 = pm.getPolygonTexture(0);
    for (int i = 0; i < end; i++) {

      uv0 = new SimpleVector(0, 0, 0);
      uv1 = new SimpleVector(0, SUBTEXTURE, 0);
      uv2 = new SimpleVector(SUBTEXTURE, 0, 0);

      ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
      ti.add(t2Id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
      pm.setPolygonTexture(i++, ti);

      uv0 = new SimpleVector(0, SUBTEXTURE, 0);
      uv1 = new SimpleVector(SUBTEXTURE, SUBTEXTURE, 0);
      uv2 = new SimpleVector(SUBTEXTURE, 0, 0);

      ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
      ti.add(t2Id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
      pm.setPolygonTexture(i, ti);
then in your vertex controller
Code: [Select]
  if (polyindex < maxPolygonID) {

            textureIndexX = VesselRenderer.SUBTEXTURE * (int) ((depth * 2) % 8);
            textureIndexY = VesselRenderer.SUBTEXTURE * (int) ((depth * 2) / 8);

            uv0 = new SimpleVector(textureIndexX, textureIndexY, 0);
            uv1 = new SimpleVector(textureIndexX,
                textureIndexY + VesselRenderer.INTERNALSUBTEXTURE, 0);
            uv2 = new SimpleVector(textureIndexX + VesselRenderer.INTERNALSUBTEXTURE,
                textureIndexY, 0);
            ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
            ti.add(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
            pm.setPolygonTexture(polyindex++, ti);

            uv0 = new SimpleVector(textureIndexX + VesselRenderer.INTERNALSUBTEXTURE, textureIndexY
                + VesselRenderer.INTERNALSUBTEXTURE, 0);
            ti = new TextureInfo(t1, uv1.x, uv1.y, uv0.x, uv0.y, uv2.x, uv2.y);
            ti.add(t1, uv1.x, uv1.y, uv0.x, uv0.y, uv2.x, uv2.y, TextureInfo.MODE_REPLACE);
            pm.setPolygonTexture(polyindex++, ti);

          }


initialise using these methods
Code: [Select]
     obj.calcNormals();
      // make sure to attach the controller before calling build() or otherwise, the object will be
      // compiled to static geometry and won't reflect any changes to the mesh.
      obj.getMesh().setVertexController(m_channelController, false);
      obj.compile(true, false);
      obj.build();

18
Support / Re: Adding / modifying textures on a plane primitive on the fly.
« on: November 28, 2013, 09:58:23 am »
Yes a different colored texture based on height. It does not have to be so large that was just so that I could visualize the texture tile as it where. this is to show the depth of a channel like a topography. 16 *16 could work.
no problems I think.

19
Support / Re: Adding / modifying textures on a plane primitive on the fly.
« on: November 28, 2013, 09:34:16 am »
Hi Yes this is at run time.
So it will have to be by group.
So you are saying create a master texture that has in my case.
30 textures of different shades.
Then change the coords of each polygon to point to the correct shade.
can you give me a brief example of this.
ie i have a texture map of 1024*1024 and 4 shades in this map
so 0,0,512,512 would be one next would be 0,512,512,1024 not sure if thats correct but you know what I mean.
Thanks
Dave 

20
Hi I resolved this by adding 3 textures of 0,0, size with different colors really simple and quick for a single texture object.
Code: [Select]
   tm.addTexture("conered", new Texture(0, 0, red));
      tm.addTexture("conegreen", new Texture(0, 0, green));
      tm.addTexture("coneorange", new Texture(0, 0, orange));

  if (channelDepth - reallocation.y < 1) {
      coneobj.setTexture("conered");

    }
    else if (channelDepth - reallocation.y < 2) {
      coneobj.setTexture("coneorange");

    }
    else {
      if (overlayBitmap != null) {
        coneobj.setTexture("conegreen");

      }
    }



21
Support / Adding / modifying textures on a plane primitive on the fly.
« on: November 28, 2013, 04:57:53 am »
Hi
I Have manged to get most of my visual effects working. However I have once again become stuck on changing textures based on the deformed plane height. spent over 2 days trying to work this one out.
If I change them to different incremental textures at the retexture stage. I see similar to what I expect see image each polygon clearly visible. Although I am not 100% on the output except that there are 2 polys per square.
 
When I try to get a polygon and apply a new texture. all the textures go back to my default texture and no polygons are visible any more.
I am sure this is just a misunderstanding of how to change the texture.
Any help greatly appreciated.
this is from my vertexcontroller that sets the z value that is done in a loop outside of this snippet.
When this code is applied it seems to apply to all the the polygons ( as if  there is one poly per column).

Code: [Select]
if (polyindex < maxPolygonID) {
            int depthiD = TextureManager.getInstance().getTextureID("depth" + (int) data % 29);
            if (depthiD == -1) {
             depthiD =  TextureManager.getInstance().getTextureID("depth0");

            }
            Logger.log("texture id = " + depthiD + "data = " + (int) data + "polyindex ="
                + polyindex);
            int t1 = pm.getPolygonTexture(polyindex);
            uv0 = pm.getTextureUV(polyindex, 0);
            uv1 = pm.getTextureUV(polyindex, 1);
            uv2 = pm.getTextureUV(polyindex, 2);
            TextureInfo ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
            ti.add(depthiD, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_MODULATE);
            pm.setPolygonTexture(polyindex++, ti);

            t1 = pm.getPolygonTexture(polyindex);
            uv0 = pm.getTextureUV(polyindex, 0);
            uv1 = pm.getTextureUV(polyindex, 1);
            uv2 = pm.getTextureUV(polyindex, 2);
            ti = new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
           ti.add(depthiD, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_MODULATE);
            pm.setPolygonTexture(polyindex++, ti);
          }
Second attachment is with this code. It seems to upset the whole texture.
https://www.dropbox.com/sh/0epa1c6jved3dxu/XGq4d9ItAu

22
I had this
Code: [Select]
tm.addTexture("platform", new Texture(0, 0, 0));
TextureInfo coneTex = new TextureInfo(tm.getTextureID("platform"));
    coneTex.add(tm.getTextureID("normals"), TextureInfo.MODE_MODULATE);
    tm.unloadTexture(fb, tm.getTexture("platform"));
    tm.replaceTexture("platform", new Texture(128, 128, red));


or
Code: [Select]
    tm.unloadTexture(fb, tm.getTexture("platform"));
    tm.replaceTexture("platform", new Texture(128, 128, green));

I just want to do this if possible.

 depthColor = green;
        coneobj.setAdditionalColor(depthColor);

Dave

23
  Solved :) :) :)
Code: [Select]
  if (i < length) {
          d[i++].z = data;
        }
        if (i < length - 2) {
          // if d[i].x  equals the last vector write the vector again.
          if (d[i - 1].x == d[i].x)
            d[i++].z = data;
        }

24
My panel is a partial window into a huge 3900*2000 map of which each point contains a depth, each tile in the map  that contains  uniuqe data is 348*348 this size is the optimum size. They are placed into a 5*10 grid.
If try to create a panel the same size as the tile the task just takes to long and never seems to return (allocating lots of memory).
So my initial attempt failed so I reduced the panel down until it worked.
Any recommendations gladly considered.
So now I scroll the panel and then refresh it when new data is required. That works quite well.
The x and y are just pointers into my data set.
So when  y is 0 I then write to 2 vertex locations. E.g. top edge. So which other edges require special treatment.
I just need to know where there will be 2 vertices representing one coord so to speak.
For instance my array is 174*174
The first 384 values in the mesh represent the top edge.
So where are they other duplicates. Left edge or right edge both ?
Does the last line of their panel also require 2 vertices. I have not observed this.
Just my panel data appears scewed.
Thanks for your help.
One other question is it possible to change the color of each vertex simply?


25
Hi
I have just spent a couple of days looking for bug in my code to finally work out it is not a bug but how the plane mesh is structured.
Here is what I think I have found by trial and error.
The first row of the mesh contains double the normal data of a normal row?
Writing the same data twice works for this case ie  dest[i++].z twice if row = 0
The array I have created is 174 *174
but the length comes back 30625 not 30276 as expected.
So it is 175 *175
So I assume I need to also add another duplicate point per row in the mesh. but where?
Any help gratefully received trail and error is to time consuming.
Thanks  code attached from my controller apply code 
Dave
Code: [Select]

 SimpleVector[] d = getDestinationMesh();
 i=0;
 int length = d.length;
 for (y = 0; y <= VesselRenderer.PANELSIZE; y++) {
      for (x = 0; x <= VesselRenderer.PANELSIZE; x++) {

        float data = (float) getData(x + VesselRenderer.m_panelxoffset, y
            + VesselRenderer.m_panelyoffset);
        // because I do not know where else to duplicate check length and do not go out of array bounds
        if (i < length) {
          d[i++].z = data;

          if (y == 0)
            d[i++].z = data;
        }
      }

    }


26
Support / Re: vertex controller problem.
« on: November 18, 2013, 12:47:35 am »
Hi Thanks for the reply and example.
It still did not work as expected but it did give me a good idea of where I was going wrong. Here is my final working code for any one else who has this issue.

Code: [Select]
     m_channel = Primitives.getPlane(PLANESIZE, 10);
      m_channel.setAdditionalColor(new RGBColor(0, 0, 0));
      m_channel.rotateX(PI / 2);
      // m_channel.rotateMesh();
      // m_channel.clearRotation();
      m_channel.setSpecularLighting(true);
      TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("channel"));
      m_channel.setTexture(ti);
      reTexture(m_channel, "channel", 5f);
      m_channel.disableVertexSharing();
      // enabling lazy transforms means do not transform this object in the future. Ok for the water
      // but nothing else
      // m_channel.forceGeometryIndices(true);
      m_channel.setCulling(true);
      m_channelController = new ChannelController();

      // Calc Normals must be done now otherwise the plane becomes a black texture.
      m_channel.calcNormals();

      // make sure to attach the controller before calling build() or otherwise, the object will be
      // compiled to static geometry and won't reflect any changes to the mesh.
      m_channel.getMesh().setVertexController(m_channelController, false);
      m_channel.build();
      // Deform the channel do this as a background task
      UpdateMapTask task = new UpdateMapTask(bathyfiles, m_channel, m_shipGpsLat, m_shipGpsLong);
      task.execute();
       m_world.addObject(m_channel);


and in the async background task
Code: [Select]
@Override
  protected String doInBackground(Void... params) {
    List<Tile> tiles = bathyFiles.getTileset(shipgpslong, shipgpslat);
    Logger.log(m_tag + " updating map to new coords " + shipgpslat + " lat " + shipgpslong
        + " long");
    bathyFiles.buildMapWindow(tiles, shipgpslong, shipgpslat);
    channel.getMesh().applyVertexController();
    channel.touch();
    return null;
  }
So the issue was no normals had been calculated when I ported from your example because I had textures.
The root cause was I was doing this more than once.
 channelMesh.setVertexController(controller, false);
which I think was breaking (creating a new link) to the mesh.
Dave


27
Support / Re: vertex controller problem.
« on: November 15, 2013, 11:08:49 am »
Yep I tried that just in case.
I will send you a simplified test case as soon as I can.

28
Support / Re: vertex controller problem.
« on: November 15, 2013, 04:34:57 am »
I have updated the code snippet above to show the changes you recommend. It now displays the first planemesh as it should.
However when I try to update the mesh nothing happens it is as if it is compiled to a static geometry. As you suggested in your first response.
If I do not apply the mesh in the first updatetask the mesh stays flat as it should. then the next time I call the updatetask with a flag to update the mesh. it still stays flat.
putting the build just before I add the plane to the world does not display the plane.
Dave


 

29
Support / Re: vertex controller problem.
« on: November 13, 2013, 11:26:01 pm »
Thanks for the prompt response. How ever that seems worse. I loose the plane altogether if I wait for the vertex controller. here is the relevant code it is on AE
I hope it is something stupid.  ;)

Code: [Select]
    m_channel = Primitives.getPlane(PLANESIZE, 10);
      m_channel.setAdditionalColor(new RGBColor(0, 0, 0));
      m_channel.rotateX(PI / 2);
      m_channel.setSpecularLighting(true);
      TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("channel"));
      m_channel.setTexture(ti);
      reTexture(m_channel, "channel", 5f);
      m_channel.disableVertexSharing();
      // enabling lazy transforms means do not transform this object in the future. Ok for the water
      // but nothing else
      m_channel.forceGeometryIndices(true);
      m_channel.setCulling(true);

      // Deform the channel do this as a background task
      // make sure to attach the controller before calling build() or otherwise, the object will be
      // compiled to static geometry and won't reflect any changes to the mesh.
      m_channelMesh = m_channel.getMesh();
      m_controller = new Mod();
      m_channel.build();
      UpdateMapTask task = new UpdateMapTask(bathyfiles, m_controller, m_channelMesh, m_channel, m_shipGpsLat,
          m_shipGpsLong);
      task.execute();
      while (MainActivity.m_UpdateinProgress){
        try {
          Thread.sleep(5);
        }
        catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      m_world.addObject(m_channel);


and the async task
Code: [Select]
  private final static String m_tag = "UpdateMapDataTask";
  private BathyFiles bathyFiles;
  private GenericVertexController controller;
  private Mesh channelMesh;
  private Object3D channel; 
  private double shipgpslong, shipgpslat;

  /**
   * This task is called to pre fetch the next map data
   *
   * @param m_controller
   */
  public UpdateMapTask(BathyFiles bathyfiles, GenericVertexController m_controller,
      Mesh m_channelMesh, Object3d m_channel, double m_shipGpsLat, double m_shipGpsLong) {
    bathyFiles = bathyfiles;
    controller = m_controller;
    channelMesh = m_channelMesh;
    shipgpslong = m_shipGpsLong;
    shipgpslat = m_shipGpsLat;
    channel=m_channel;
  }

  @Override
  protected void onPreExecute() {
    MainActivity.m_UpdateinProgress = true;
  }

  @Override
  protected String doInBackground(Void... params) {
    List<Tile> tiles = bathyFiles.getTileset(shipgpslong, shipgpslat);
    Logger.log(m_tag + " updating map to new coords " + shipgpslat + " lat " + shipgpslong
        + " long");
    bathyFiles.buildMapWindow(tiles, shipgpslong, shipgpslat);
    boolean success = channelMesh.setVertexController(controller, false);
    Logger.log(m_tag + " success " + success);
    channelMesh.applyVertexController();
    channel.touch();
    return null;
  }

  @Override
  protected void onPostExecute(String test) {
    MainActivity.m_UpdateinProgress = false;
    Logger.log(m_tag + " finished updating map to new coords " + shipgpslat + " lat " + shipgpslong
        + " long");
  }

After trying for a few hours to work this out the only way I got it to work sort of was to create a new plane object delete the old object from the world and then add the new plane. This will let me continue working for now but I really need to know what is wrong.  My plane mesh is quite large so I don't want to keep allocating and de allocating. It does take a long time to do that. without recreating the new plane it only takes .5 of a second for my code to complete. with the new object it takes over 10 seconds.
Dave

30
Support / vertex controller problem.(Solved)
« on: November 13, 2013, 12:39:22 pm »
I am having an issue applying a vertex controller to a plane. Once I have added it to the world.
I update the plane in an async task it works fine the first time (this is done  just before i add the object to the world), but the second time even though it succeeds there is no visible change to my plane.
Is there anything else I need to do to get the new mesh to appear  instead of the old mesh.
I tried touch but that did nothing.
My next test is to apply a second vertex before I add the object to the world.
Any thoughts or explanation on why the second apply does not work .lazy transformations are off.
Dave

Pages: 1 [2] 3