Cloning

Hello friends!



I’ve got two j3o objects.



scene.j3o - has 20 empty nodes with different location and rotation.

trap.j3o - object looks like mine with its own collision boundingbox.



scene.j3o hierarchy nodes:

+trap_empties ← root

-trap.001

-trap.002

-trap.003

-trap.004



-trap.020





I want to clone trap.j3o to empty nodes of scene.j3o with dynamic loading (traps will be exploding when they collide with character). How to make it? Thank you!





[java]

public class Test extends SimpleApplication {







Node scene;

Spatial trap;





public static void main(String[] args) {

Test app = new TriangleCollisionTest();

app.start();

}



@Override

public void simpleInitApp() {

// Create two boxes

scene = (Node) assetManager.loadModel(“Scenes/scene.j3o”);

rootNode.attachChild(scene);







// load a character from jme3test-test-data

trap = assetManager.loadModel(“Models/trap.j3o”);

rootNode.attachChild(trap);

}

}

[/java]

A users did something similar with blender and jMP:

http://www.youtube.com/watch?v=IDHMWsu_PqA

This should work for you too, just use “Add liked node” and Ctrl-C and Ctrl-P to copy nodes. A hint: you should update to the latest nightly version of jME/jMP to use AssetLinkNodes because there were some unexpected changes in the system lately and the AssetLinkNodes produced by Alpha-2 and Alpha-3 will not load anymore in later versions, sorry.

Thank you, but it’s cool for static objects. but what if i want to apply some kind of AI or logics for traps? it would be cool to clone a dynamic object (character, interacting items) to a node object. How do you think?

Its all scenegraph objects (Spatials), if your special Node implements the read() and write() methods properly it will work in this economy.

I apologize for annoying, but cold you have a look at my code (I archived entire project basicGame2.zip 300kb)? http://files.mail.ru/4EG1G2

I’ve got some problems with detaching clones. Is it possible to solve such a problem?



The main problem in code is here i suppose:

[java]

BoundingVolume bv = golem.getWorldBound();

geom1.collideWith(bv, results);



for (int i = 0; i < results.size(); i++) {



String hit = results.getCollision(i).getGeometry().getName();

boolean u = geom1.getChild(hit).removeFromParent();



System.out.println("* Collision #" + i + u);



}



[/java]



Only one quad should die per collision, but they die in big quantity. Controls: ikjl (when you press f6).



Thank you beforehand!!!

Well you remove everything the ray hits, you do a loop.

I cannot understant,… sorry.

You remove every result of the collision, so everything that the model bounding volume (not ray) touches will be removed. So probably you remove the floor, models next to the golem etc.

Thank you Nomen for your replies!!! My code based on TrisCollisionTest.java and HelloPicking.java.

There is no Ray in my code.

I just can understand what exactly i change in my code. Collision works, but children remove in big quantity (not what expected).



geom1 (traps.j3o) has many nodes with instances and they should to be removed when collide with golem (episode_01_enemy_01.j3o). But they are removed in different order. Chaos.



Entire project: http://files.mail.ru/4EG1G2



Entire code:



[java]

import com.jme3.app.SimpleApplication;

import com.jme3.bounding.BoundingVolume;

import com.jme3.collision.CollisionResults;

import com.jme3.input.controls.AnalogListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.scene.Spatial;

import com.jme3.input.KeyInput;

import com.jme3.scene.Node;

import java.util.List;



public class collision_test2 extends SimpleApplication {







Node geom1;

Spatial golem;





public static void main(String[] args) {

collision_test2 app = new collision_test2();

app.start();

}



@Override

public void simpleInitApp() {





geom1 = (Node) assetManager.loadModel(“Scenes/episode_01/traps.j3o”);

rootNode.attachChild(geom1);









golem = assetManager.loadModel(“Models/episode_01/episode_01_enemy_01.j3o”);

rootNode.attachChild(golem);







// Create input

inputManager.addMapping(“MoveRight”, new KeyTrigger(KeyInput.KEY_L));

inputManager.addMapping(“MoveLeft”, new KeyTrigger(KeyInput.KEY_J));

inputManager.addMapping(“MoveUp”, new KeyTrigger(KeyInput.KEY_I));

inputManager.addMapping(“MoveDown”, new KeyTrigger(KeyInput.KEY_K));



inputManager.addListener(analogListener, new String[]{

“MoveRight”, “MoveLeft”, “MoveUp”, “MoveDown”

});

}

private AnalogListener analogListener = new AnalogListener() {



public void onAnalog(String name, float value, float tpf) {

if (name.equals(“MoveRight”)) {

geom1.move(2 * tpf, 0, 0);

}



if (name.equals(“MoveLeft”)) {

geom1.move(-2 * tpf, 0, 0);

}



if (name.equals(“MoveUp”)) {

geom1.move(0, 2 * tpf, 0);

}



if (name.equals(“MoveDown”)) {

geom1.move(0, -2 * tpf, 0);

}

}

};



@Override

public void simpleUpdate(float tpf) {

rootNode.updateGeometricState();



CollisionResults results = new CollisionResults();







BoundingVolume bv = golem.getWorldBound();

geom1.collideWith(bv, results);



for (int i = 0; i < results.size(); i++) {



String hit = results.getCollision(i).getGeometry().getName();





boolean u = geom1.getChild(hit).removeFromParent();

// List u = geom1.getChildren();

System.out.println("* Collision #" + i + u);



}



if (results.size() > 0) {



}







}

}



[/java]