New Instance of Spatial

hi all,



I would like to ask how would I be able to make a new instance of Spatial where I would like to add the following properties and methods…



String objectType;
String model_ID;

public void setObjectType(String objType){
    objectType = objType;
}
public String getObjectType(){
     return objectType;
}
public void setModelID(String modID){
    model_ID = modID;
}
public String getModelID(){
     return model_ID;
}

Hey mhelz,



Extending Spatials in jME is generally not recommended (there was actually just a thread in the past day or two that demonstrated this), but technically you could do it like this



public class AwesomeSpatial extends Spatial{
private String objectType;
private String model_ID;

public AwesomeSpatial(String name, String objectType, String model_ID){
super(name);
this.objectType=objectType;
this.model_ID=model_ID;
}

public void setObjectType(String objType){
    objectType = objType;
}
public String getObjectType(){
     return objectType;
}
public void setModelID(String modID){
    model_ID = modID;
}
public String getModelID(){
     return model_ID;
}
}



What I would suggest is something much less intrusive, which is formatting the names of your spatials in a specific way, like:

mySpatial.setName("My Cool Spatial" + "$" + objectType + "#" + model_ID);



now to get your object type and model ID you would do:

String objectType = mySpatial.getName().substring(mySpatial.getName().lastIndexOf("$")+1, mySpatial.getName().lastIndexOf("#"));
String model_ID = mySpatial.getName().substring(mySpatial.getName().lastIndexOf("#")+1, mySpatial.getName().length());



Hope that helps :)

actually, I was thinking of the same solution as was the last you have stated there sbook before I posted this topic… but doing that now would mess up my whole code… so I thought if I had a new instance of spatial with these new properties I could just get away with just setting and getting the properties… nevertheless, thanks for the quick reply… I'll be trying this out in a bit…