implement attach point offset and tweak human
This commit is contained in:
		
							parent
							
								
									74a9ea4a5f
								
							
						
					
					
						commit
						55cebdf33a
					
				| @ -236,7 +236,7 @@ | ||||
|                     "equipPointId" : "handRight", | ||||
|                     "bone" : "MiddleLower.R", | ||||
|                     "offsetVector" : [], | ||||
|                     "offsetRotation" : [], | ||||
|                     "offsetRotation" : [0.3057,0.2926,0.09933,0.9006], | ||||
|                     "equipClassWhitelist" : [ | ||||
|                         "tool", | ||||
|                         "weapon", | ||||
|  | ||||
| @ -148,6 +148,7 @@ public class EntityDataStrings { | ||||
|     public static final String ATTACH_PARENT = "attachParent"; | ||||
|     public static final String ATTACH_TARGET_BONE = "attachTargetBone"; | ||||
|     public static final String ATTACH_CHILDREN_LIST = "attachChildrenList"; | ||||
|     public static final String ATTACH_ROTATION_OFFSET = "attachRotationOffset"; | ||||
|      | ||||
|     /* | ||||
|     Item Entity | ||||
|  | ||||
| @ -72,7 +72,7 @@ public class EquipState { | ||||
|                             meshMask.queueMesh(modelName, toDraw); | ||||
|                         } | ||||
|                         //attach to parent bone | ||||
|                         AttachUtils.attachEntityToEntityAtBone(parent, toEquip, point.getBone()); | ||||
|                         AttachUtils.attachEntityToEntityAtBone(parent, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); | ||||
|                         //make uncollidable | ||||
|                         if(toEquip.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ | ||||
|                             CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||
| @ -88,7 +88,7 @@ public class EquipState { | ||||
|             } else { | ||||
|                 //since we're not replacing meshes we must be attaching to a bone | ||||
|                 equipMap.put(point.getEquipPointId(),toEquip); | ||||
|                 AttachUtils.attachEntityToEntityAtBone(parent, toEquip, point.getBone()); | ||||
|                 AttachUtils.attachEntityToEntityAtBone(parent, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); | ||||
|                 if(toEquip.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ | ||||
|                     CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||
|                     Globals.collisionEngine.deregisterPhysicsObject(rigidBody); | ||||
|  | ||||
| @ -23,11 +23,12 @@ import org.joml.Vector3f; | ||||
| public class AttachUtils { | ||||
|      | ||||
|      | ||||
|     public static void attachEntityToEntityAtBone(Entity parent, Entity toAttach, String boneName){ | ||||
|     public static void attachEntityToEntityAtBone(Entity parent, Entity toAttach, String boneName, Quaternionf rotation){ | ||||
|         Globals.entityManager.registerBoneAttachedEntity(toAttach); | ||||
|         toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true); | ||||
|         toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent); | ||||
|         toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName); | ||||
|         toAttach.putData(EntityDataStrings.ATTACH_ROTATION_OFFSET, rotation); | ||||
|         if(parent.containsKey(EntityDataStrings.ATTACH_CHILDREN_LIST)){ | ||||
|             getChildrenList(parent).add(toAttach); | ||||
|         } else { | ||||
| @ -44,6 +45,8 @@ public class AttachUtils { | ||||
|                 String targetBone; | ||||
|                 if((targetBone = (String)currentEntity.getData(EntityDataStrings.ATTACH_TARGET_BONE))!=null){ | ||||
|                     Actor parentActor = EntityUtils.getActor(parent); | ||||
|                     //get offset rotation | ||||
|                     Quaternionf offsetRotation = getRotationOffset(currentEntity); | ||||
|                     //transform bone space | ||||
|                     Vector3d position = new Vector3d(parentActor.getBonePosition(targetBone)); | ||||
|                     position = position.mul(((Vector3f)EntityUtils.getScale(parent))); | ||||
| @ -57,7 +60,12 @@ public class AttachUtils { | ||||
| //                    Quaternionf rotation = parentActor.getBoneRotation(targetBone); | ||||
| //                    EntityUtils.getRotation(currentEntity).set(rotation).normalize(); | ||||
|                     Vector3d facingAngle = CreatureUtils.getFacingVector(parent); | ||||
|                     EntityUtils.getRotation(currentEntity).rotationTo(new Vector3f(0,0,1), new Vector3f((float)facingAngle.x,(float)facingAngle.y,(float)facingAngle.z)).mul(parentActor.getBoneRotation(targetBone)).normalize(); | ||||
|                     //calculate rotation of model | ||||
|                     EntityUtils.getRotation(currentEntity) | ||||
|                         .rotationTo(new Vector3f(0,0,1), new Vector3f((float)facingAngle.x,(float)facingAngle.y,(float)facingAngle.z)) | ||||
|                         .mul(parentActor.getBoneRotation(targetBone)) | ||||
|                         .mul(offsetRotation) | ||||
|                         .normalize(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| @ -84,6 +92,10 @@ public class AttachUtils { | ||||
|     public static Entity getParent(Entity e){ | ||||
|         return (Entity)e.getData(EntityDataStrings.ATTACH_PARENT); | ||||
|     } | ||||
| 
 | ||||
|     protected static Quaternionf getRotationOffset(Entity e){ | ||||
|         return (Quaternionf)e.getData(EntityDataStrings.ATTACH_ROTATION_OFFSET); | ||||
|     } | ||||
|      | ||||
|     public static boolean hasChildren(Entity e){ | ||||
|         return e.containsKey(EntityDataStrings.ATTACH_CHILDREN_LIST) && !getChildrenList(e).isEmpty(); | ||||
| @ -104,4 +116,9 @@ public class AttachUtils { | ||||
|             parent.putData(EntityDataStrings.ATTACH_CHILDREN_LIST, childrenEntities); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static Quaternionf getEquipPointRotationOffset(List<Float> values){ | ||||
|         return new Quaternionf(values.get(0),values.get(1),values.get(2),values.get(3)); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -8,6 +8,8 @@ import electrosphere.entity.types.creature.CreatureUtils; | ||||
| import electrosphere.entity.types.item.ItemUtils; | ||||
| import electrosphere.game.server.ai.creature.MillAbout; | ||||
| 
 | ||||
| import org.joml.Quaterniond; | ||||
| import org.joml.Quaternionf; | ||||
| import org.joml.Vector3d; | ||||
| import org.joml.Vector3f; | ||||
| 
 | ||||
| @ -23,7 +25,7 @@ public class UnitUtils { | ||||
|         EntityUtils.getScale(goblin).set(0.005f); | ||||
|         //give evil goblin sword | ||||
|         Entity goblinSword = ItemUtils.spawnBasicItem("Katana"); | ||||
|         AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031"); | ||||
|         AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031", new Quaternionf()); | ||||
|         //attach ai to evil goblin | ||||
|         MillAbout.attachToCreature(goblin); | ||||
| //        MindlessAttacker.attachToCreature(goblin); | ||||
|  | ||||
| @ -37,6 +37,7 @@ import java.util.Iterator; | ||||
| import java.util.Random; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import org.joml.Matrix4f; | ||||
| import org.joml.Quaterniond; | ||||
| import org.joml.Quaternionf; | ||||
| import org.joml.Vector3f; | ||||
| import org.lwjgl.glfw.*; | ||||
|  | ||||
| @ -1,5 +1,8 @@ | ||||
| package electrosphere.net.client.protocol; | ||||
| 
 | ||||
| import org.joml.Quaterniond; | ||||
| import org.joml.Quaternionf; | ||||
| 
 | ||||
| import electrosphere.entity.Entity; | ||||
| import electrosphere.entity.EntityUtils; | ||||
| import electrosphere.entity.types.attach.AttachUtils; | ||||
| @ -79,7 +82,7 @@ public class EntityProtocol { | ||||
|                 Entity parent = Globals.entityManager.getEntityFromId(message.gettargetID()); | ||||
|                 LoggerInterface.loggerNetworking.DEBUG("Attach " + message.getentityID() + " to " + message.gettargetID() + " on bone " + message.getbone()); | ||||
|                 if(child != null && parent != null){ | ||||
|                     AttachUtils.attachEntityToEntityAtBone(parent, child, message.getbone()); | ||||
|                     AttachUtils.attachEntityToEntityAtBone(parent, child, message.getbone(), new Quaternionf()); | ||||
|                 } | ||||
|                 break; | ||||
|             case MOVEUPDATE: | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user