|
|
|
@@ -1,6 +1,5 @@
|
|
|
|
|
package com.aaaaahhhhhhh.bananapuncher714.mesh.physics;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
@@ -30,7 +29,7 @@ import com.aaaaahhhhhhh.bananapuncher714.mesh.command.validator.InputValidatorDo
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.command.validator.InputValidatorInt;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.command.validator.sender.SenderValidatorPlayer;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.EnvironmentHandler;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.MeshEnvironment;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.McMeshEnvironmentPlugin;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.objects.ChunkLocation;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.objects.ChunkMesh;
|
|
|
|
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.util.NmsUtil;
|
|
|
|
@@ -52,15 +51,12 @@ import com.jme3.math.Quaternion;
|
|
|
|
|
import com.jme3.math.Vector3f;
|
|
|
|
|
|
|
|
|
|
public class McMeshPhysicsPlugin extends JavaPlugin {
|
|
|
|
|
private static final int TIME_STEPS = 5;
|
|
|
|
|
private static final int TIME_STEPS = 10;
|
|
|
|
|
private static final float SIMULATION_SPEED = 1f;
|
|
|
|
|
|
|
|
|
|
private MeshEnvironment environment;
|
|
|
|
|
|
|
|
|
|
private PhysicsSpace space;
|
|
|
|
|
private boolean paused = false;
|
|
|
|
|
private boolean teleportOnDeactivate = false;
|
|
|
|
|
private float tick = 0;
|
|
|
|
|
private Map< PhysicsCollisionObject, AuxiliaryDisplayStruct > linkedDisplays = new HashMap< PhysicsCollisionObject, AuxiliaryDisplayStruct >();
|
|
|
|
|
private Set< PhysicsCollisionObject > active = new HashSet< PhysicsCollisionObject >();
|
|
|
|
|
private Map< ChunkLocation, PhysicsRigidBody > chunks = new HashMap< ChunkLocation, PhysicsRigidBody >();
|
|
|
|
@@ -72,10 +68,13 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
|
|
|
|
|
space = new PhysicsSpace( BroadphaseType.DBVT );
|
|
|
|
|
space.setAccuracy( 1f / ( TIME_STEPS * 20f ) );
|
|
|
|
|
|
|
|
|
|
environment = new MeshEnvironment( this, new File( getDataFolder(), "environment" ) );
|
|
|
|
|
environment.setHandler( new EnvironmentHandler() {
|
|
|
|
|
JavaPlugin.getPlugin( McMeshEnvironmentPlugin.class ).registerHandler( new EnvironmentHandler() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onMeshLoad( ChunkLocation location, ChunkMesh mesh ) {
|
|
|
|
|
if ( !location.getWorld().getName().equalsIgnoreCase( "world" ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now, create a physics object from the chunk mesh
|
|
|
|
|
final IndexedMesh nativeMesh = mesh.toIndexedMesh();
|
|
|
|
|
// Enable quantized AABB compression... hopefully that doesn't mess with the accuracy or anything...
|
|
|
|
@@ -99,12 +98,20 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onMeshUnload( ChunkLocation location, ChunkMesh mesh ) {
|
|
|
|
|
space.removeCollisionObject( chunks.get( location ) );
|
|
|
|
|
if ( !location.getWorld().getName().equalsIgnoreCase( "world" ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
space.removeCollisionObject( chunks.remove( location ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onMeshUpdate( ChunkLocation location, ChunkMesh mesh ) {
|
|
|
|
|
// Now, create a physics object from the chunk mesh
|
|
|
|
|
if ( !location.getWorld().getName().equalsIgnoreCase( "world" ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now, create a physics object from the chunk mesh
|
|
|
|
|
final IndexedMesh nativeMesh = mesh.toIndexedMesh();
|
|
|
|
|
// Enable quantized AABB compression... hopefully that doesn't mess with the accuracy or anything...
|
|
|
|
|
final MeshCollisionShape meshCollision = new MeshCollisionShape( true, nativeMesh );
|
|
|
|
@@ -132,7 +139,7 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
|
|
|
|
|
if ( !paused ) {
|
|
|
|
|
// Update the real world with the physics space objects
|
|
|
|
|
space.distributeEvents();
|
|
|
|
|
space.update( tick, TIME_STEPS );
|
|
|
|
|
space.update( SIMULATION_SPEED / 20f, TIME_STEPS );
|
|
|
|
|
|
|
|
|
|
for ( Iterator< Entry< PhysicsCollisionObject, AuxiliaryDisplayStruct > > it = linkedDisplays.entrySet().iterator(); it.hasNext(); ) {
|
|
|
|
|
Entry< PhysicsCollisionObject, AuxiliaryDisplayStruct > entry = it.next();
|
|
|
|
@@ -187,8 +194,6 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
|
|
|
|
|
disp.display.setInterpolationDuration( 2 );
|
|
|
|
|
disp.display.setTransformationMatrix( transMat.mul( transformRot ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tick += SIMULATION_SPEED / 20f;
|
|
|
|
|
}
|
|
|
|
|
}, 0, 1 );
|
|
|
|
|
}
|
|
|
|
|