Visualised Collisions & broken as hell player model
This commit is contained in:
parent
aff4c2a57a
commit
ffb7b842af
16 changed files with 220 additions and 25 deletions
0
resources/models/VisualCollision/CollisionCube.colmesh
Normal file
0
resources/models/VisualCollision/CollisionCube.colmesh
Normal file
BIN
resources/models/VisualCollision/CollisionCube.idx
Normal file
BIN
resources/models/VisualCollision/CollisionCube.idx
Normal file
Binary file not shown.
15
resources/models/VisualCollision/CollisionCube.json
Normal file
15
resources/models/VisualCollision/CollisionCube.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"ID": "CollisionCube",
|
||||
"Meshes": [
|
||||
{
|
||||
"ID": "mesh_0",
|
||||
"MaterialID": "CollisionCube-mat-1",
|
||||
"OffsetVertex": 0,
|
||||
"VertexSize": 1344,
|
||||
"OffsetIndex": 0,
|
||||
"IndexSize": 144
|
||||
}
|
||||
],
|
||||
"VertexPath": "resources/models/VisualCollision/CollisionCube.vtx",
|
||||
"IndexPath": "resources/models/VisualCollision/CollisionCube.idx"
|
||||
}
|
||||
4
resources/models/VisualCollision/CollisionCube.mtl
Normal file
4
resources/models/VisualCollision/CollisionCube.mtl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Made in Blockbench 5.1.4
|
||||
newmtl m_b3ff62ec-245d-6ae0-3e07-f637264603d3
|
||||
map_Kd CollisionCubeTexture.png
|
||||
newmtl none
|
||||
49
resources/models/VisualCollision/CollisionCube.obj
Normal file
49
resources/models/VisualCollision/CollisionCube.obj
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Made in Blockbench 5.1.4
|
||||
mtllib CollisionCube.mtl
|
||||
|
||||
o mesh
|
||||
v 0.5 1 0.5
|
||||
v 0.5 1 -0.5
|
||||
v 0.5 0 0.5
|
||||
v 0.5 0 -0.5
|
||||
v -0.5 1 0.5
|
||||
v -0.5 1 -0.5
|
||||
v -0.5 0 0.5
|
||||
v -0.5 0 -0.5
|
||||
vt 0.3333333333333333 1
|
||||
vt 0 1
|
||||
vt 0 0.6666666666666667
|
||||
vt 0.3333333333333333 0.6666666666666667
|
||||
vt 0.3333333333333333 0.33333333333333337
|
||||
vt 0.3333333333333333 0.6666666666666667
|
||||
vt 0 0.6666666666666667
|
||||
vt 0 0.33333333333333337
|
||||
vt 0.3333333333333333 0.6666666666666667
|
||||
vt 0.6666666666666666 0.6666666666666667
|
||||
vt 0.6666666666666666 1
|
||||
vt 0.3333333333333333 1
|
||||
vt 0.6666666666666666 0.33333333333333337
|
||||
vt 0.6666666666666666 0.6666666666666667
|
||||
vt 0.3333333333333333 0.6666666666666667
|
||||
vt 0.3333333333333333 0.33333333333333337
|
||||
vt 0.3333333333333333 0
|
||||
vt 0.3333333333333333 0.33333333333333337
|
||||
vt 0 0.33333333333333337
|
||||
vt 0 0
|
||||
vt 1 1
|
||||
vt 0.6666666666666666 1
|
||||
vt 0.6666666666666666 0.6666666666666667
|
||||
vt 1 0.6666666666666667
|
||||
vn 1 0 0
|
||||
vn -1 0 0
|
||||
vn 0 1 0
|
||||
vn 0 -1 0
|
||||
vn 0 0 1
|
||||
vn 0 0 -1
|
||||
usemtl m_b3ff62ec-245d-6ae0-3e07-f637264603d3
|
||||
f 2/1/1 1/2/1 3/3/1 4/4/1
|
||||
f 7/5/2 5/6/2 6/7/2 8/8/2
|
||||
f 5/9/3 1/10/3 2/11/3 6/12/3
|
||||
f 4/13/4 3/14/4 7/15/4 8/16/4
|
||||
f 3/17/5 1/18/5 5/19/5 7/20/5
|
||||
f 6/21/6 2/22/6 4/23/6 8/24/6
|
||||
BIN
resources/models/VisualCollision/CollisionCube.vtx
Normal file
BIN
resources/models/VisualCollision/CollisionCube.vtx
Normal file
Binary file not shown.
BIN
resources/models/VisualCollision/CollisionCubeTexture.png
Normal file
BIN
resources/models/VisualCollision/CollisionCubeTexture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 126 B |
44
resources/models/VisualCollision/CollisionCube_mat.json
Normal file
44
resources/models/VisualCollision/CollisionCube_mat.json
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
[
|
||||
{
|
||||
"ID": "CollisionCube-mat-0",
|
||||
"TexturePath": "",
|
||||
"NormalTexturePath": "",
|
||||
"MetalRoughnessMap": "",
|
||||
"DiffuseColour": {
|
||||
"X": 0.6,
|
||||
"Y": 0.6,
|
||||
"Z": 0.6,
|
||||
"W": 1.0
|
||||
},
|
||||
"Roughness": 0.0,
|
||||
"Metallic": 0.0
|
||||
},
|
||||
{
|
||||
"ID": "CollisionCube-mat-1",
|
||||
"TexturePath": "resources\\models\\VisualCollision\\CollisionCubeTexture.png",
|
||||
"NormalTexturePath": "",
|
||||
"MetalRoughnessMap": "",
|
||||
"DiffuseColour": {
|
||||
"X": 0.6,
|
||||
"Y": 0.6,
|
||||
"Z": 0.6,
|
||||
"W": 1.0
|
||||
},
|
||||
"Roughness": 0.0,
|
||||
"Metallic": 0.0
|
||||
},
|
||||
{
|
||||
"ID": "CollisionCube-mat-2",
|
||||
"TexturePath": "",
|
||||
"NormalTexturePath": "",
|
||||
"MetalRoughnessMap": "",
|
||||
"DiffuseColour": {
|
||||
"X": 0.6,
|
||||
"Y": 0.6,
|
||||
"Z": 0.6,
|
||||
"W": 1.0
|
||||
},
|
||||
"Roughness": 0.0,
|
||||
"Metallic": 0.0
|
||||
}
|
||||
]
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.VisualisedCollisionActor;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.primitives.AABBf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class ConvexMesh {
|
||||
public static class Face{
|
||||
|
|
@ -21,6 +22,8 @@ public class ConvexMesh {
|
|||
public Vector3f BottomLeftBack = new Vector3f(Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE);
|
||||
public Vector3f TopRightForward = new Vector3f(Float.MIN_VALUE,Float.MIN_VALUE,Float.MIN_VALUE);
|
||||
|
||||
public static final Map<UUID, ConvexMesh> MeshRegistry = new HashMap<>();
|
||||
|
||||
public final List<Vector3f> LocalVertices = new ArrayList<>();
|
||||
public final List<Face> Faces = new ArrayList<>();
|
||||
public final List<int[]> Edges = new ArrayList<>();
|
||||
|
|
@ -28,6 +31,12 @@ public class ConvexMesh {
|
|||
public final Vector3f Position = new Vector3f();
|
||||
public final Quaternionf Orientation = new Quaternionf();
|
||||
public Vector3f hxhyhz = new Vector3f();
|
||||
public UUID MeshID;
|
||||
|
||||
public ConvexMesh(){
|
||||
MeshID = UUID.randomUUID();
|
||||
MeshRegistry.put(MeshID, this);
|
||||
}
|
||||
|
||||
public Vector3f WorldVertex(int i) {
|
||||
Vector3f vertex = new Vector3f(LocalVertices.get(i));
|
||||
|
|
@ -105,6 +114,9 @@ public class ConvexMesh {
|
|||
|
||||
int[][] e = {{0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{0,4},{1,5},{2,6},{3,7}};
|
||||
mesh.Edges.addAll(Arrays.asList(e));
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
PrimaryRuntime.GetEngineInstance().scene().AddActor(new VisualisedCollisionActor("VISUALISEDACTOR" + mesh.MeshID.toString(), mesh.Position, mesh.MeshID));
|
||||
}
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,8 +89,15 @@ public class GameCore implements GameLogic {
|
|||
MelonaData = ModelLoader.LoadModel("resources/models/cube/Cube.json");
|
||||
CubeModelID = MelonaData.ID();
|
||||
List<MaterialData> MelonaMat = ModelLoader.LoadMaterials("resources/models/cube/Cube_mat.json");
|
||||
var CollisionVisualisationData = ModelLoader.LoadModel("resources/models/VisualCollision/CollisionCube.json");
|
||||
VisualisedCollisionActor.CollisionCubeModelID = CollisionVisualisationData.ID();
|
||||
List<MaterialData> CollisionVisualisationMat = ModelLoader.LoadMaterials("resources/models/VisualCollision/CollisionCube_mat.json");
|
||||
List<MaterialData> materials = new ArrayList<>();
|
||||
|
||||
var Melona = ModelLoader.LoadModel("resources/models/melona/melona.json");
|
||||
List<MaterialData> MelonaMaterial = ModelLoader.LoadMaterials("resources/models/melona/melona_mat.json");
|
||||
PlayerActor.MelonaModelID = Melona.ID();
|
||||
|
||||
MusketData = ModelLoader.LoadModel("resources/models/musket/musket.json");
|
||||
List<MaterialData> MusketMat = ModelLoader.LoadMaterials("resources/models/musket/musket_mat.json");
|
||||
RevolverData = ModelLoader.LoadModel("resources/models/Revolver/Revolver.json");
|
||||
|
|
@ -121,9 +128,13 @@ public class GameCore implements GameLogic {
|
|||
materials.addAll(RevolverMat);
|
||||
}
|
||||
materials.addAll(MelonaMat);
|
||||
materials.addAll(CollisionVisualisationMat);
|
||||
materials.addAll(MelonaMaterial);
|
||||
materials.addAll(MusketMat);
|
||||
materials.addAll(RevolverMat);
|
||||
models.add(MelonaData);
|
||||
models.add(CollisionVisualisationData);
|
||||
models.add(Melona);
|
||||
models.add(MusketData);
|
||||
models.add(RevolverData);
|
||||
Camera camera = scene.GetCamera();
|
||||
|
|
@ -429,7 +440,14 @@ public class GameCore implements GameLogic {
|
|||
|
||||
@Override
|
||||
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
|
||||
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
for (int i = 0; i < VisualisedCollisionActor.CollisionVisuals.size(); i++) {
|
||||
VisualisedCollisionActor.CollisionVisuals.get(i).Update();
|
||||
}
|
||||
for(int i = 0; i < ActorElement.ElementNames.size(); i++){
|
||||
ActorElement.ActorElementRegistry.get(ActorElement.ElementNames.get(i)).UpdateModelMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public class ActorElement extends Actor {
|
|||
public static List<String> ElementNames = new ArrayList<>();
|
||||
|
||||
private String ParentID = "NULL";
|
||||
public boolean RenderOnTopOfPlayer = false;
|
||||
public Vector3f RotationStrength = new Vector3f(1f,1f,1f);
|
||||
|
||||
|
||||
public ActorElement(String ID, String ModelID, String ParentID, Vector3f PositionOffset){
|
||||
|
|
@ -29,6 +31,8 @@ public class ActorElement extends Actor {
|
|||
ElementNames.add(ID);
|
||||
this.ParentID = ParentID;
|
||||
SetPositionOffset(PositionOffset);
|
||||
Scale.set(1f,1f,1f);
|
||||
Rotation.identity();
|
||||
UpdateModelMatrix();
|
||||
ActorElementRegistry.put(ID,this);
|
||||
}
|
||||
|
|
@ -72,7 +76,7 @@ public class ActorElement extends Actor {
|
|||
Actor Parent = Actor.Actors.get(ParentID);
|
||||
if(Parent == null) return;
|
||||
ModelMatrix.translateLocal(TemporaryVector.set(PivotOffset).add(AdditionalPivotOffset));
|
||||
ModelMatrix.translationRotateScale(new Vector3f(Parent.GetPosition()), new Quaternionf(Parent.GetRotation()).add(Rotation), Scale);
|
||||
ModelMatrix.translationRotateScale(new Vector3f(Parent.GetPosition()), new Quaternionf(Parent.GetRotation()), Scale);
|
||||
ModelMatrix.translate(PositionOffset);
|
||||
ModelMatrix.translateLocal(TemporaryVector.negate());
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,17 @@ import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlayerActor extends Actor{
|
||||
|
||||
public static String MelonaModelID = "melona";
|
||||
|
||||
public String AttachedCameraID;
|
||||
public final Vector3f CameraOffset = new Vector3f(0,0,0);
|
||||
Camera PlayerCam;
|
||||
|
|
@ -20,6 +25,9 @@ public class PlayerActor extends Actor{
|
|||
this.AttachedCameraID = AttachedCameraID;
|
||||
PlayerCam = Camera.CameraRegistry.get(AttachedCameraID);
|
||||
super(ID, ModelID, Position);
|
||||
if(!Objects.equals(ClientConnectionThread.OwnedActorID, ID) && !RenderThread.Headless && !PrimaryRuntime.Server){
|
||||
PrimaryRuntime.GetEngineInstance().scene().AddActor(new ActorElement("PlayerModel" + ID, MelonaModelID, ID,new Vector3f(0,0,0)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.RenderThread;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VisualisedCollisionActor extends Actor{
|
||||
public static final List<VisualisedCollisionActor> CollisionVisuals = new ArrayList<>();
|
||||
public static String CollisionCubeModelID;
|
||||
final UUID LinkedMesh;
|
||||
public VisualisedCollisionActor(String ID, Vector3f Position, UUID LinkedMesh) {
|
||||
super(ID, CollisionCubeModelID, Position);
|
||||
if(!PrimaryRuntime.Server && !RenderThread.Headless) {
|
||||
this.LinkedMesh = LinkedMesh;
|
||||
CollisionVisuals.add(this);
|
||||
} else{
|
||||
this.LinkedMesh = null;
|
||||
}
|
||||
}
|
||||
public void Update(){
|
||||
if(PrimaryRuntime.Server || RenderThread.Headless) return;
|
||||
ConvexMesh mesh = ConvexMesh.MeshRegistry.get(LinkedMesh);
|
||||
if(mesh != null) {
|
||||
SetScale(new Vector3f(mesh.hxhyhz).mul(2.01f));
|
||||
SetPosition(new Vector3f(mesh.Position.x,mesh.Position.y,mesh.Position.z));
|
||||
SetPositionOffset(new Vector3f(0,-mesh.hxhyhz.y/3f,0));
|
||||
SetRotation(mesh.Orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ public class ClientConnectionThread implements Runnable{
|
|||
if(!IncomingPacketQueue.isEmpty()){
|
||||
Packet packet;
|
||||
while((packet = IncomingPacketQueue.poll()) != null){
|
||||
System.out.println("Packet: " + packet.PacketTypeByte);
|
||||
// System.out.println("Packet: " + packet.PacketTypeByte);
|
||||
Actor Target = Actor.Actors.get(packet.TargetID);
|
||||
Vector3f vector3f = new Vector3f();
|
||||
String stringdata = "";
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public class ServerConnectionThread implements Runnable{
|
|||
public static void ProcessClientPacket(Packet packet){
|
||||
ServerConnectionThread sender = ConnectedClients.get(packet.ClientID);
|
||||
if(sender == null) return;
|
||||
System.out.println("Packet: " + packet.PacketTypeByte);
|
||||
//System.out.println("Packet: " + packet.PacketTypeByte);
|
||||
|
||||
Actor Target = Actor.Actors.get(packet.TargetID);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Actor;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.ActorElement;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.IScene;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DeferredRendering.MultiRenderTargetAttachments;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.DynamicMesh.DynamicTerrainMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline.DefaultPipeline;
|
||||
|
|
@ -21,6 +23,7 @@ import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.SwapChain.SwapChain;
|
|||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.util.shaderc.Shaderc;
|
||||
|
|
@ -416,6 +419,8 @@ public class DeferredSceneRender implements SceneRenderer {//dynamic rendering
|
|||
if(i < Actors.size()) {
|
||||
var Actor = Actors.get(i);
|
||||
if(Actor != null) {
|
||||
if(Actor instanceof ActorElement &&( !((ActorElement) Actor).RenderOnTopOfPlayer && Objects.equals(((ActorElement) Actor).GetParentID(), ClientConnectionThread.OwnedActorID) || new Vector3f().set(Actor.GetPosition()).sub(instance.scene().GetCamera().GetPosition()).absolute().lengthSquared() < 4f)) continue;
|
||||
else {
|
||||
VulkanModel model = modelsCache.GetModel(Actor.GetModelID());
|
||||
List<VulkanMesh> VkMeshList = model.GetVkMeshList();
|
||||
int MeshCount = VkMeshList.size();
|
||||
|
|
@ -441,6 +446,7 @@ public class DeferredSceneRender implements SceneRenderer {//dynamic rendering
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetPushConstants(VkCommandBuffer CmdHandle, Matrix4f ModelMatrix, int MaterialIndex){
|
||||
ModelMatrix.get(0,PushConstBuffer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue