Procházet zdrojové kódy

Add support for connected bodies

Added center of mass
Removed delta velocities
tags/v1.1.0
NorbiPeti před 4 roky
rodič
revize
269d30b0db
5 změnil soubory, kde provedl 47 přidání a 49 odebrání
  1. +16
    -0
      GamecraftModdingAPI/Blocks/BlockEngine.cs
  2. +0
    -11
      GamecraftModdingAPI/Blocks/RemovalEngine.cs
  3. +0
    -15
      GamecraftModdingAPI/Players/PlayerEngine.cs
  4. +23
    -19
      GamecraftModdingAPI/SimBody.cs
  5. +8
    -4
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs

+ 16
- 0
GamecraftModdingAPI/Blocks/BlockEngine.cs Zobrazit soubor

@@ -4,6 +4,8 @@ using Gamecraft.Wires;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.GUI.Hotbar.Colours;
using RobocraftX.Physics;
using RobocraftX.Scene.Simulation;
using Svelto.DataStructures;
using Svelto.ECS;

@@ -126,6 +128,20 @@ namespace GamecraftModdingAPI.Blocks
return ret.ToArray();
}

public SimBody[] GetConnectedSimBodies(uint id)
{
var joints = entitiesDB.QueryEntities<JointEntityStruct>(MachineSimulationGroups.JOINTS_GROUP);
var list = new FasterList<SimBody>(4);
foreach (var joint in joints)
{
if (joint.jointState == JointState.Broken) continue;
if (joint.connectedEntityA == id) list.Add(new SimBody(joint.connectedEntityB));
else if (joint.connectedEntityB == id) list.Add(new SimBody(joint.connectedEntityA));
}

return list.ToArray();
}

#if DEBUG
public EntitiesDB GetEntitiesDB()
{


+ 0
- 11
GamecraftModdingAPI/Blocks/RemovalEngine.cs Zobrazit soubor

@@ -28,17 +28,6 @@ namespace GamecraftModdingAPI.Blocks

public void Ready()
{
/*CommandManager.AddCommand(new SimpleCustomCommandEngine(() =>
{
var block = BlockUtility.GetBlockLookedAt(LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB), entitiesDB);
if (block.HasValue)
{
RemoveBlock(block.Value);
Log.Output("Removed block.");
}
else
Log.Output("No block found where you're looking at.");
}, "removeCube", "Removes the cube you're looking at."));*/
}

public EntitiesDB entitiesDB { get; set; }


+ 0
- 15
GamecraftModdingAPI/Players/PlayerEngine.cs Zobrazit soubor

@@ -249,21 +249,6 @@ namespace GamecraftModdingAPI.Players
: maxDistance;
if (rayCast.hit && rayCast.distance <= distance)
return rayCast.hitEgid;
/*if (rayCast.hit)
{
*Logging.MetaDebugLog("RayCast EGID: " + rayCast.hitEgid);
var d = AccessTools.Field(typeof(ExclusiveGroup), "_knownGroups").GetValue(null) as
Dictionary<string, ExclusiveGroupStruct>;
foreach (var groupStruct in d)
{
if (groupStruct.Value == rayCast.hitEgid.groupID)
{
Logging.MetaDebugLog("Group name: " + groupStruct.Key);
break; //SIMULATION_BODIES_GROUP
}
}*
//Logging.MetaDebugLog("Position: " + Block.GetBlockPositionTest(rayCast.hitEgid));
}*/

return null;
}


+ 23
- 19
GamecraftModdingAPI/SimBody.cs Zobrazit soubor

@@ -1,5 +1,4 @@
using Gamecraft.Wires;
using RobocraftX.Common;
using RobocraftX.Common;
using RobocraftX.Physics;
using Svelto.ECS;
using Unity.Mathematics;
@@ -23,6 +22,10 @@ namespace GamecraftModdingAPI
{
}

/// <summary>
/// The position of this body. When setting the position, update the position of the connected bodies as well,
/// otherwise unexpected forces may arise.
/// </summary>
public float3 Position
{
get => GetStruct().position;
@@ -39,19 +42,7 @@ namespace GamecraftModdingAPI
{
get => GetStruct().angularVelocity;
set => GetStruct().angularVelocity = value;
}

public float3 DeltaVelocity
{
get => GetStruct().deltaVelocity;
set => GetStruct().deltaVelocity = value;
}

public float3 DeltaAngularVelocity
{
get => GetStruct().deltaAngularVelocity;
set => GetStruct().deltaAngularVelocity = value;
}
} //Delta versions are used internally, can't be set or get

public float3 Rotation
{
@@ -68,14 +59,27 @@ namespace GamecraftModdingAPI
public float Mass
{
get => math.rcp(GetStruct().physicsMass.InverseMass);
set => GetStruct().physicsMass.InverseMass = math.rcp(value);
//set => GetStruct().physicsMass.InverseMass = math.rcp(value);
}

public float3 CenterOfMass
{
get => GetStruct().physicsMass.CenterOfMass;
//set => GetStruct().physicsMass.CenterOfMass = value;
}

/// <summary>
/// Whether the body can be moved or static.
/// </summary>
public bool Static => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(Id).isStatic; //Setting it doesn't have any effect

/// <summary>
/// Whether the body can be moved or static
/// The rigid bodies connected to this one via functional joints (broken ones don't count).
/// </summary>
public bool Static => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(Id).isStatic;
//Setting it doesn't have any effect
public SimBody[] GetConnectedBodies()
{
return Block.BlockEngine.GetConnectedSimBodies(Id.entityID);
}

private ref RigidBodyEntityStruct GetStruct()
{


+ 8
- 4
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs Zobrazit soubor

@@ -216,6 +216,11 @@ namespace GamecraftModdingAPI.Tests
{
Logging.CommandLog("SimBody: " + body);
body.Position += new float3(0, 10, 0);
foreach (var bodyConnectedBody in body.GetConnectedBodies())
{
Logging.CommandLog("Moving " + bodyConnectedBody);
bodyConnectedBody.Position += new float3(0, 10, 0);
}
}
}).Build();

@@ -296,9 +301,8 @@ namespace GamecraftModdingAPI.Tests
if (body == null) return "Body: none";
return "Body: " + (body.Static ? "static" : "non-static")
+ "\nAt: " + body.Position + " - rotated: " + body.Rotation
+ "\nWith mass: " + body.Mass
+ "\nVelocity: " + body.Velocity + " - angular: " + body.AngularVelocity
+ "\nDelta velocity: " + body.DeltaVelocity + " - angular: " + body.DeltaAngularVelocity;
+ "\nWith mass: " + body.Mass + " - center: " + body.CenterOfMass
+ "\nVelocity: " + body.Velocity + " - angular: " + body.AngularVelocity;
}

return "Switching modes...";
@@ -310,7 +314,7 @@ namespace GamecraftModdingAPI.Tests
if (modsString != null) return modsString;
StringBuilder sb = new StringBuilder("Installed mods:");
foreach (var plugin in PluginManager.Plugins)
sb.Append("\n" + plugin);
sb.Append("\n" + plugin.Name + " - " + plugin.Version);
return modsString = sb.ToString();
}



Načítá se…
Zrušit
Uložit