From 56ed405aeab0a9b3ab24549c70bf107ccc528c8b Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 24 Jul 2024 13:57:16 -0400 Subject: [PATCH] devtools --- assets/Data/creatures/human.json | 3 +- docs/src/progress/renderertodo.md | 1 + .../entity/state/equip/ClientEquipState.java | 10 +++--- .../entity/state/equip/ServerEquipState.java | 4 +-- .../entity/types/attach/AttachUtils.java | 5 +-- .../data/creature/type/equip/EquipPoint.java | 32 +++++++++++++++---- .../menu/debug/ImGuiEntityMacros.java | 29 +++++++++++++---- 7 files changed, 62 insertions(+), 22 deletions(-) diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index 1ae58a3c..55788c59 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -256,7 +256,8 @@ "bone" : "Hand.R", "firstPersonBone" : "hand.R", "offsetVector" : [0,0,0], - "offsetRotation" : [-0.334,0.145,-0.28,0.89], + "offsetRotationThirdPerson" : [-0.334,0.145,-0.28,0.89], + "offsetRotationFirstPerson" : [0.923,-0.143,-0.232,0.24], "canBlock" : true, "equipClassWhitelist" : [ "tool", diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 380a51e8..f187e402 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -450,6 +450,7 @@ Attacker ai tree (07/24/2024) 2 Hand katana Switching between first and third person +Devtools for updating first person attachment rotations # TODO diff --git a/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java b/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java index f8e0f8f4..6f519ac6 100644 --- a/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java @@ -131,7 +131,7 @@ public class ClientEquipState implements BehaviorTree { meshMask.queueMesh(modelName, toDraw); } //attach to parent bone - AttachUtils.clientAttachEntityToEntityAtBone(parent, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.clientAttachEntityToEntityAtBone(parent, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); //make uncollidable if(toEquip.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ DBody rigidBody = (DBody)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); @@ -148,9 +148,9 @@ public class ClientEquipState implements BehaviorTree { //does not depend on the type of creature, must be attaching to a bone equipMap.put(point.getEquipPointId(),toEquip); if(Globals.controlHandler.cameraIsThirdPerson()){ - AttachUtils.clientAttachEntityToEntityAtBone(parent, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.clientAttachEntityToEntityAtBone(parent, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); } else { - AttachUtils.clientAttachEntityToEntityAtBone(Globals.firstPersonEntity, toEquip, point.getFirstPersonBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.clientAttachEntityToEntityAtBone(Globals.firstPersonEntity, toEquip, point.getFirstPersonBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationFirstPerson())); } if(toEquip.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ DBody rigidBody = (DBody)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); @@ -341,14 +341,14 @@ public class ClientEquipState implements BehaviorTree { EquipPoint point = this.getEquipPoint(occupiedPoint); Entity toEquip = this.equipMap.get(point.getEquipPointId()); AttachUtils.clientDetatchEntityFromEntityAtBone(Globals.firstPersonEntity, toEquip); - AttachUtils.clientAttachEntityToEntityAtBone(Globals.playerEntity, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.clientAttachEntityToEntityAtBone(Globals.playerEntity, toEquip, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); } } else { for(String occupiedPoint : this.getEquippedPoints()){ EquipPoint point = this.getEquipPoint(occupiedPoint); Entity toEquip = this.equipMap.get(point.getEquipPointId()); AttachUtils.clientDetatchEntityFromEntityAtBone(Globals.playerEntity, toEquip); - AttachUtils.clientAttachEntityToEntityAtBone(Globals.firstPersonEntity, toEquip, point.getFirstPersonBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.clientAttachEntityToEntityAtBone(Globals.firstPersonEntity, toEquip, point.getFirstPersonBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationFirstPerson())); } } } diff --git a/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java b/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java index 51132831..c3d83ee5 100644 --- a/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java @@ -114,7 +114,7 @@ public class ServerEquipState implements BehaviorTree { String modelName = whitelistItem.getModel(); Globals.assetManager.addModelPathToQueue(modelName); //attach to parent bone - AttachUtils.serverAttachEntityToEntityAtBone(parent, inWorldItem, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.serverAttachEntityToEntityAtBone(parent, inWorldItem, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); //make uncollidable if(inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ DBody rigidBody = (DBody)inWorldItem.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); @@ -131,7 +131,7 @@ public class ServerEquipState implements BehaviorTree { } else { //does not depend on the type of creature equipMap.put(point.getEquipPointId(),inWorldItem); - AttachUtils.serverAttachEntityToEntityAtBone(parent, inWorldItem, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.serverAttachEntityToEntityAtBone(parent, inWorldItem, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); if(inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){ DBody rigidBody = (DBody)inWorldItem.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); Realm inWorldRealm = Globals.realmManager.getEntityRealm(inWorldItem); diff --git a/src/main/java/electrosphere/entity/types/attach/AttachUtils.java b/src/main/java/electrosphere/entity/types/attach/AttachUtils.java index 65766f82..69f5e010 100644 --- a/src/main/java/electrosphere/entity/types/attach/AttachUtils.java +++ b/src/main/java/electrosphere/entity/types/attach/AttachUtils.java @@ -572,8 +572,9 @@ public class AttachUtils { * @param parentEntity * @return The list of entities that are attached to this parent entity, or null if undefined */ - public static LinkedList getChildrenList(Entity parentEntity){ - return (LinkedList)parentEntity.getData(EntityDataStrings.ATTACH_CHILDREN_LIST); + @SuppressWarnings("unchecked") //as long as we only ever access this value via the getters and setters in this class, this assumption should always be correct + public static List getChildrenList(Entity parentEntity){ + return (List)parentEntity.getData(EntityDataStrings.ATTACH_CHILDREN_LIST); } /** diff --git a/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java b/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java index 7e0fd4de..d49730b5 100644 --- a/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java +++ b/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java @@ -16,7 +16,9 @@ public class EquipPoint { //the offset to apply to items that are attached to the bone List offsetVector; //the rotation to apply to the items that are attached to the bone - List offsetRotation; + List offsetRotationThirdPerson; + //the rotation to apply to the items that are attached to the view model's bone + List offsetRotationFirstPerson; //signals that this equip point can block boolean canBlock; //the equip classes that are whitelisted for this equip point @@ -55,19 +57,37 @@ public class EquipPoint { } /** - * Gets the rotation to apply to the items that are attached to the bone + * [Third Person] + * Gets the rotation to apply to the items that are attached to the third person model's bone * @return the rotation */ - public List getOffsetRotation(){ - return offsetRotation; + public List getOffsetRotationThirdPerson(){ + return offsetRotationThirdPerson; } /** * Sets the offset rotation (used primarily for debug and engine testing) * @param offsetRotation The new offset rotation */ - public void setOffsetRotation(List offsetRotation){ - this.offsetRotation = offsetRotation; + public void setOffsetRotationThirdPerson(List offsetRotation){ + this.offsetRotationThirdPerson = offsetRotation; + } + + /** + * [First Person] + * Gets the rotation to apply to the items that are attached to the view model's bone + * @return the rotation + */ + public List getOffsetRotationFirstPerson(){ + return offsetRotationFirstPerson; + } + + /** + * Sets the offset rotation (used primarily for debug and engine testing) + * @param offsetRotation The new offset rotation + */ + public void setOffsetRotationFirstPerson(List offsetRotation){ + this.offsetRotationFirstPerson = offsetRotation; } /** diff --git a/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java b/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java index fe97942e..91534477 100644 --- a/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java +++ b/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java @@ -161,7 +161,10 @@ public class ImGuiEntityMacros { equipStateView.setCallback(new ImGuiWindowCallback() { //stores the edited rotation values - float[] rotationValues = new float[]{ + float[] rotationValuesFirstPerson = new float[]{ + 0,0,0 + }; + float[] rotationValuesThirdPerson = new float[]{ 0,0,0 }; @@ -176,18 +179,32 @@ public class ImGuiEntityMacros { ImGui.text("Has item equipped: " + (clientEquipState.getEquippedItemAtPoint(point.getEquipPointId()) != null)); ImGui.text("Bone (Third Person): " + point.getBone()); ImGui.text("Bone (First Person): " + point.getFirstPersonBone()); - ImGui.text("Rotation: " + AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); - if(ImGui.sliderFloat3("Rotation (In Euler along x,y,z)", rotationValues, 0, (float)(Math.PI * 2))){ - Quaterniond rotation = new Quaterniond().rotateXYZ(rotationValues[0], rotationValues[1], rotationValues[2]); + ImGui.text("[Third Person] Rotation: " + AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); + if(ImGui.sliderFloat3("[Third Person] Rotation (In Euler along x,y,z)", rotationValuesThirdPerson, 0, (float)(Math.PI * 2))){ + Quaterniond rotation = new Quaterniond().rotateXYZ(rotationValuesThirdPerson[0], rotationValuesThirdPerson[1], rotationValuesThirdPerson[2]); List newValues = new LinkedList(); newValues.add((float)rotation.x); newValues.add((float)rotation.y); newValues.add((float)rotation.z); newValues.add((float)rotation.w); - point.setOffsetRotation(newValues); + point.setOffsetRotationThirdPerson(newValues); Entity equippedEntity = clientEquipState.getEquippedItemAtPoint(point.getEquipPointId()); if(equippedEntity != null){ - AttachUtils.setRotationOffset(equippedEntity, AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation())); + AttachUtils.setRotationOffset(equippedEntity, AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationThirdPerson())); + } + } + ImGui.text("[First Person] Rotation: " + AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationFirstPerson())); + if(ImGui.sliderFloat3("[First Person] Rotation (In Euler along x,y,z)", rotationValuesFirstPerson, 0, (float)(Math.PI * 2))){ + Quaterniond rotation = new Quaterniond().rotateXYZ(rotationValuesFirstPerson[0], rotationValuesFirstPerson[1], rotationValuesFirstPerson[2]); + List newValues = new LinkedList(); + newValues.add((float)rotation.x); + newValues.add((float)rotation.y); + newValues.add((float)rotation.z); + newValues.add((float)rotation.w); + point.setOffsetRotationFirstPerson(newValues); + Entity equippedEntity = clientEquipState.getEquippedItemAtPoint(point.getEquipPointId()); + if(equippedEntity != null){ + AttachUtils.setRotationOffset(equippedEntity, AttachUtils.getEquipPointRotationOffset(point.getOffsetRotationFirstPerson())); } } }