浏览代码

-Working on diagnosing wave physics

/demo-work-customrenderer
Mike Geig 5 年前
当前提交
177f9cd8
共有 8 个文件被更改,包括 1963 次插入36 次删除
  1. 30
      Assets/Unity Physics Items/BuoyantObject_DOTS.cs
  2. 935
      Assets/Unity Physics Items/Physics Scene.unity
  3. 18
      Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs
  4. 2
      Assets/Unity Physics Items/Systems/DriveSystem.cs
  5. 4
      Assets/Unity Physics Items/Systems/InputSystem.cs
  6. 2
      Packages/com.verasl.water-system/Scripts/BuoyantObject.cs
  7. 1001
      Assets/Unity Physics Items/Junk.unity
  8. 7
      Assets/Unity Physics Items/Junk.unity.meta

30
Assets/Unity Physics Items/BuoyantObject_DOTS.cs


//Will be called by the PhysicsConversionSystem
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
//Calculat all initial values
//Add data needed for buoyancy
BuoyantData data = new BuoyantData();
data.type = _buoyancyType;
data.voxelResolution = voxelResolution;

data.baseAngularDrag = baseAngularDrag;
dstManager.AddComponentData(entity, data);
dstManager.AddBuffer<VoxelOffset>(entity);
dstManager.AddBuffer<VoxelHeight>(entity);
//Add center of mass. This is why we had to use a custom conversion system since we needed the physics stuff to be converted before this step
dstManager.AddBuffer<VoxelOffset>(entity);
dstManager.AddBuffer<VoxelHeight>(entity);
//Initialize the voxel and height buffers
//Add engine position as first point
//offsets.Add(new VoxelOffset { Value = engine.enginePosition - centerOfMass });
//heights.Add(new VoxelHeight { Value = float3.zero });
//Add the rest of the positions
offsets.Add(new VoxelOffset { Value = voxels[i] - centerOfMass });// transform.TransformPoint(voxels[i]) - transform.position }); // << Is this right?
offsets.Add(new VoxelOffset { Value = voxels[i] - centerOfMass });// transform.TransformPoint(voxels[i]) - transform.position }); // << Is this right?
body.Convert(conversionSystem.GetPrimaryEntity(body), dstManager, conversionSystem);
//if (body)
body.Convert(conversionSystem.GetPrimaryEntity(body), dstManager, conversionSystem);
engine.Convert(conversionSystem.GetPrimaryEntity(engine), dstManager, conversionSystem);
if (engine)
engine.Convert(conversionSystem.GetPrimaryEntity(engine), dstManager, conversionSystem);
}
struct DebugDrawing

935
Assets/Unity Physics Items/Physics Scene.unity
文件差异内容过多而无法显示
查看文件

18
Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs


protected override JobHandle OnUpdate(JobHandle inputDeps)
{
//Debug.Log(string.Format("DeltaTime: {0}, Time.time {1}, Calc Delta: {2}", Time.deltaTime, Time.time, Time.time - lastTime));
//lastTime = Time.time;
Debug.Log(string.Format("DeltaTime: {0}, Time.time {1}, Calc Delta: {2}", Time.deltaTime, Time.time, Time.time - lastTime));
lastTime = Time.time;
var job = new ForceJob()
{
dt = Time.deltaTime,

float submergedAmount = 0f;
//Debug.Log("new pass: " + entity.ToString());
float3 avPos = float3.zero;
float3 avForce = float3.zero;
float avgHeight = 0;
int total = 0;
var entityTransform = new RigidTransform(rot.Value, pos.Value);

//entity.ApplyImpulse(force, wp);//RB.AddForceAtPosition(force, wp);
avgHeight += force.y;
total++;
avPos += offsets[i].Value;
avForce += math.rotate(math.inverse(rot.Value), force * dt);
// Debug.Log("Average height: " + avgHeight / total);
//Debug.Log("Avg force: " + avForce / total + " Avg pos: " + avPos / total);
//Debug.Log($"Avg force: {avForce / total} Avg pos: {avPos / total}");
data.percentSubmerged = Mathf.Lerp(data.percentSubmerged, submergedAmount, 0.25f);
damping.Linear = data.baseDrag + (data.baseDrag * (data.percentSubmerged * 10f));
damping.Angular = data.baseAngularDrag + (data.percentSubmerged * 0.5f);
//data.percentSubmerged = Mathf.Lerp(data.percentSubmerged, submergedAmount, 0.25f);
//damping.Linear = data.baseDrag + (data.baseDrag * (data.percentSubmerged * 10f));
//damping.Angular = data.baseAngularDrag + (data.percentSubmerged * 0.5f);
}
}

2
Assets/Unity Physics Items/Systems/DriveSystem.cs


float3 up = math.mul(rot.Value, math.up());
ComponentExtensions.ApplyLinearImpulse(ref vel, mass, force * dt);
ComponentExtensions.ApplyLinearImpulse(ref vel, mass, up * 20000f * dt);
//ComponentExtensions.ApplyLinearImpulse(ref vel, mass, up * 20000f * dt);
//ComponentExtensions.ApplyAngularImpulse(ref vel, mass, torque * dt);
//RB.AddForce(forward * modifier * horsePower, ForceMode.Acceleration); // add force forward based on input and horsepower
//RB.AddRelativeTorque(-Vector3.right * modifier, ForceMode.Acceleration);

4
Assets/Unity Physics Items/Systems/InputSystem.cs


protected override void OnUpdate()
{
//not time to start
if (Time.time < startTime)
return;
//if (Time.time < startTime)
//return;
Entities.ForEach((Entity entity, ref Translation pos, ref Rotation rot, ref DrivingData data ) =>
{

2
Packages/com.verasl.water-system/Scripts/BuoyantObject.cs


for(var i = 0; i < voxels.Length; i++) BuoyancyForce(voxels[i], heights[i].y, ref submergedAmount, ref debugInfo[i]);
Physics.SyncTransforms();
Physics.autoSyncTransforms = true;
// UpdateDrag(submergedAmount);
UpdateDrag(submergedAmount);
}
else if(_buoyancyType == BuoyancyType.Physical)
{

1001
Assets/Unity Physics Items/Junk.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Unity Physics Items/Junk.unity.meta


fileFormatVersion: 2
guid: 4c9021618b4f57942adc0278fef71036
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存