Renderer/src/main/java/electrosphere/entity/EntityUtils.java
2021-06-01 01:05:42 -04:00

90 lines
3.5 KiB
Java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package electrosphere.entity;
import electrosphere.entity.state.MovementTree;
import electrosphere.renderer.Model;
import electrosphere.main.Globals;
import electrosphere.renderer.Actor;
import electrosphere.renderer.ActorUtils;
import org.joml.Quaternionf;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class EntityUtils {
public static Vector3f getEntityPosition(Entity e){
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_POSITION);
}
public static Quaternionf getEntityRotation(Entity e){
return (Quaternionf)e.getData(EntityDataStrings.DATA_STRING_ROTATION);
}
public static Vector3f getEntityScale(Entity e){
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_SCALE);
}
public static String getEntityModelPath(Entity e){
return (String)e.getData(EntityDataStrings.DATA_STRING_MODEL_PATH);
}
public static Entity spawnDrawableEntity(String modelPath){
Entity rVal = new Entity();
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
// rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath);
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerDrawableEntity(rVal);
return rVal;
}
public static Entity spawnDrawableEntityWithPreexistingModel(String modelPath){
Entity rVal = new Entity();
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerDrawableEntity(rVal);
return rVal;
}
public static Entity spawnUIEntity(String modelPath){
Entity rVal = new Entity();
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
rVal.putData(EntityDataStrings.DATA_STRING_UI_ELEMENT, true);
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerUIEntity(rVal);
return rVal;
}
public static void cleanUpDrawableEntity(Entity e){
if(e != null){
Globals.entityManager.deregisterEntity(e);
// getEntityModelPath(e).free();
}
}
public static void setEntityID(Entity e, int id){
Globals.entityManager.overrideEntityId(e, id);
}
public static Actor getEntityActor(Entity e){
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
}
}