Mesh treatment

I wanne change a existing mesh while its in use and after that I wanne safe the modified mesh 4 later work.



Atm i only wanne shift the positions of some vertices of a Box() mesh.



How can I do this??

Atm i stuck at “VertexBuffer vertices = buffer.get(0);” and I don’t see a way to get access to the position-floats.



[java]

package jme3.own;



import java.nio.Buffer;

import java.util.Iterator;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.VertexBuffer;

import com.jme3.scene.shape.Box;

import com.jme3.util.IntMap;

import com.jme3.util.IntMap.Entry;



public class MeshTest extends SimpleApplication {



@Override

public void simpleInitApp() {

guiNode.detachAllChildren();

viewPort.setBackgroundColor(ColorRGBA.Orange);

Box box1 = new Box(new Vector3f(1, -1, 1), 1, 1, 1);

Geometry blue = new Geometry(“Box”, box1);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.Blue);

blue.setMaterial(mat1);

rootNode.attachChild(blue);

IntMap<VertexBuffer> buffer = box1.getBuffers();

for (Entry entry : buffer) {

System.out.println(entry.getValue());

}

VertexBuffer vertices = buffer.get(0);

System.out.println("vertices: "+vertices);





}



/**

  • @param args

    */

    public static void main(String[] args) {

    MeshTest test = new MeshTest();

    test.setShowSettings(false);

    test.start();



    }



    }



    [/java]



    Can u please show me the right way? :slight_smile:

[java]Mesh mesh = blue.getMesh();

mesh.getBuffer(Type.Position); [/java]



There is a custom mesh tutorial in the wiki. It’d be a good start.

hi, I already made the tutorial.

But as u see I wanne change a mesh AFTER I got it.



Building a custom mesh isn’t a problem.



But what do I have to do whit the VertexBuffer after i get it per getData().



sry for this dumb question.

If you do a

java mesh.getBuffer(Type.Position);[/java]

You’ll get all vertices as floats, each vertex consisting of 3 floats each, corresponding to x, y, z position.



You can then set them again with setBuffer().

Another way of doing it is



[java]VertexBuffer vb = mesh.getBuffer(Type.Position);

FloatBuffer fb = (FloatBuffer) vb.getData();

// modify fb

vb.updateData(fb); // make sure to call after changes to set the “update needed” flag[/java]

So many THANKS 4 your help.

now the manipulation can start^^



KR

Silberruecken