I´m trying to open and close a flower i have imported, and i want to be able to do it with the mouse.
Grab hold of a flower petal and change the top vertex of the petal to form some kind of open/close animation.
The 3d model has 25 vertexes, and the top 4 vertex points that should be draggable are 2,6,16 and 18 in the obj file.
I rewrote the convert function in ObjToJme to support testing, so if you pass along modh and modv, it opens and closes the petals of the importing model.
[java] @Override
public void convert(InputStream format, OutputStream jMEFormat, float modh, float modv)
throws IOException {
renderer = DisplaySystem.getDisplaySystem().getRenderer();
defaultMaterialGroup = new MaterialGrouping();
vertexList.clear();
textureList.clear();
normalList.clear();
genNormalList.clear();
materialSets.clear();
materialNames.clear();
inFile = new BufferedReader(new InputStreamReader(format));
String in;
curGroup = defaultMaterialGroup;
materialSets.put(defaultMaterialGroup, new ArraySet());
while ((in = inFile.readLine()) != null) {
processLine(in);
}
vertexList.set(2, new Vector3f((0.0f-(modvstfloat)), 17.7088f, (0.0f+(modhstfloat))));//open equals 2=-,+
vertexList.set(6, new Vector3f((0.0f+(modvstfloat)), 17.7088f, (0.0f+(modhstfloat))));//open equals 6=+,+
vertexList.set(16, new Vector3f((0.0f-(modvstfloat)), 17.7088f, (0.0f-(modhstfloat))));//open equals 16=-,-
vertexList.set(18, new Vector3f((0.0f+(modvstfloat)), 17.7088f, (0.0f-(modhstfloat))));//open equals 18=+,-
BinaryExporter.getInstance().save(buildStructure(null),jMEFormat);
nullAll();
}[/java]
and I use the function with
[java] Spatial map;
URL folder= GalleryApp.class.getClassLoader().getResource("data/");
URL model = GalleryApp.class.getClassLoader().getResource("data/flower.obj");
FormatConverter converter=new ObjToJme();
converter.setProperty("mtllib", folder);
converter.setProperty("texdir", folder);
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
converter.convert(model.openStream(), BO, 30, 30);
map=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
map.setLocalScale(1f);
map.setModelBound(new BoundingBox());
map.updateModelBound();
rootNode.attachChild(map);
} catch (Exception e) {
System.out.println("Failure! n" + e);
e.printStackTrace();
System.exit(0);
}[/java]
Any help would be greatly appretiated.