[SOLVED] how to assign 1 custom controll to N instances of same mesh?

hi

how do i do this in the scene editor (if possible) ?

or should it be done at runtime(programaticaly)

thx

Ctrl-C Ctrl-V the geometry after adding the control to one of them?

strange

  • the ide propose only some classes (who extends Control and AbstractControl), not other classes
  • as i try to assign a control, i get this message : “Error instantiating class”

    i checked jme code but could not find this string, something to do with the classpath ?

a) thats because only classes who extend Control are… a control… and if you started extending your own controls, read the manual, thats an antipattern really, use multiple controls, read the manual on best practices

b) read the manual on how to use custom controls they have to have an empty constructor as well

[edit] ok cloneForSpatial returned null, so… i guess thats the trick

@normen said:
a) thats because only classes who extend Control are... a control.. and if you started extending your own controls, read the manual, thats an antipattern really, use multiple controls, read the manual on best practices
b) read the manual on how to use custom controls they have to have an empty constructor as well


indeed, thx

problem is that i used constructors with parameters



like this

Code:
public Bug(.....,AssetManager assetManager, ...) {

not really nice but neaded so that the controller directs loading of assets, and constructions of objects

for example :
Code:
path = new MotionPath(); path.enableDebugShape(assetManager, rootNode);

'path' needs asset manager for construction,

but in the ide, i got no assetManager instance... :(

Need more code.



Put down the code where you instantiate such a path from your codebase. If assetManager is null then you did something wrong somewhere.

i end up beeing stuck as i would have to go through each instances imported from blender, with hundreeds of instances it is unthinkable, so i will have to do this at runtime, too bad

anyway thx

A control has access to the assetmanager in the read() method so you probably can support an empty constructor. But to add it in the first place in the SDK you’d have to create a one-class plugin to add your control type.

Edit: Hm, I guess I could support Controls that only need an AssetManager in the constructor easily… Thanks for the input :wink:

no worries man :wink:

so far i use this as a “workaround”

Code:
Spatial spatials= DataManager.LoadModel("Models/something.j3o"); List<Spatial> list = ((Node)spatials).getChildren(); Iterator<Spatial> it = list.iterator(); while(it.hasNext()) { Spatial s=it.next(); if(s.getName().startsWith("SomeBlenderModel")) { rootNode.attachChild(s); ...... add custom controls code } }

Crap. I misunderstood the whole thing. Sorry about that. :facepalm:

@madjack said:
Crap. I misunderstood the whole thing. Sorry about that. :facepalm:


well it is a pipeline thing

i have lets say 100 objects, all the same mesh, but different instance
i try to find an easy way to add a custom controller with blender or the editor
@normen said:
A control has access to the assetmanager in the read() method so you probably _can_ support an empty constructor. But to add it in the first place in the SDK you'd have to create a one-class plugin to add your control type.
Edit: Hm, I guess I could support Controls that only need an AssetManager in the constructor easily... Thanks for the input ;)


it might not solve everything althought ...

the problem is that i need to remove an object once it is hit, so i assign a RigidBodyController that implements a PhysicsCollisionListener to remove the node on collision

but i need access to the root node, how can i achieve that with a default constructor ?
Code:
package mygame.controls;

import com.jme3.asset.AssetManager;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.scene.Node;

public class MyControl extends RigidBodyControl implements PhysicsCollisionListener{
private final AssetManager assetManager;
private final Node rootNode;

public MyControl(AssetManager assetManager,Node rootNode)
{
    super(new SphereCollisionShape(2));
    this.assetManager=assetManager;
    this.rootNode=rootNode;
}

public void collision(PhysicsCollisionEvent event) {
    rootNode.detachChild(spatial);
}

}

You could check the spatial you’re attached to for a “root node” (the ancestor of the spatial that has no parent anymore).

@normen said:
You could check the spatial you're attached to for a "root node" (the ancestor of the spatial that has no parent anymore).


so obvious ... lol

but for things like that : (i forgot to add this in the code above)
Code:
bulletAppState.getPhysicsSpace().addCollisionListener(this);

sorry to be a pain, but as i dig i find boogie traps

i was also thinking of writing an ide plugin that could deal with interfacing scenes with actual game data
with a nice gui and xml editor like for materials, if not too complicated
cos it can't be avoided, i would use a default constructor in case i add the custom controll in the ide
and another constructor that would be accessed in the program to initialise runtime data

You will need to use physicsSpace.addAll() anyway. And a physicsControl gets connection to the physicsSpace then. You won’t be able to solve all issues like these but if you design your Controls slim then its possible.

@normen said:
You will need to use physicsSpace.addAll() anyway. And a physicsControl gets connection to the physicsSpace then. You won't be able to solve all issues like these but if you design your Controls slim then its possible.


does it work for collision listeners too ?

Again, as a PhysicsControl you get a reference to the PhysicsSpace.