/* * 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.collidable.CollidableTree; import electrosphere.entity.state.movement.GroundMovementTree; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.renderer.Model; import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.ActorUtils; import electrosphere.main.Globals; import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; /** * * @author amaterasu */ public class EntityUtils { public static Vector3d getPosition(Entity e){ return (Vector3d)e.getData(EntityDataStrings.DATA_STRING_POSITION); } public static Quaternionf getRotation(Entity e){ return (Quaternionf)e.getData(EntityDataStrings.DATA_STRING_ROTATION); } public static Vector3f getScale(Entity e){ return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_SCALE); } public static String getModelPath(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 Vector3d(0,0,0)); rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity()); rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true); 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 Vector3d(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_DRAW, true); rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true); 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 Vector3d(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; } /** * Spawns an entity that has a position in the world, but isn't necessarily drawable * @return the entity */ public static Entity spawnSpatialEntity(){ Entity rVal = new Entity(); // rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath); rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0)); rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity()); rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); Globals.entityManager.registerEntity(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 getActor(Entity e){ return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR); } public static CollidableTree getCollidableTree(Entity e){ return (CollidableTree)e.getData(EntityDataStrings.COLLIDABLE_TREE); } public static void setVisible(Entity entity, boolean visible){ entity.putData(EntityDataStrings.DATA_STRING_DRAW, visible); } public static void setDraw(Entity entity, boolean draw){ entity.putData(EntityDataStrings.DATA_STRING_DRAW, draw); } public static boolean getDraw(Entity entity){ return (boolean)entity.getData(EntityDataStrings.DATA_STRING_DRAW); } }