private void Update() { switch (_buoyancyType) { case BuoyancyType.NonPhysical: { var t = transform; var vec = t.position; vec.y = Heights[0].y + waterLevelOffset; t.position = vec; t.up = Vector3.Slerp(t.up, _normals[0], Time.deltaTime); break; } case BuoyancyType.NonPhysicalVoxel: // do the voxel non-physical break; case BuoyancyType.Physical: LocalToWorldJob.CompleteJob(_guid); GetVelocityPoints(); break; case BuoyancyType.PhysicalVoxel: LocalToWorldJob.CompleteJob(_guid); GetVelocityPoints(); break; default: throw new ArgumentOutOfRangeException(); } GerstnerWavesJobs.UpdateSamplePoints(ref _samplePoints, _guid); GerstnerWavesJobs.GetData(_guid, ref Heights, ref _normals); }
private void LocalToWorldConversion() { if (_buoyancyType != BuoyancyType.Physical && _buoyancyType != BuoyancyType.PhysicalVoxel) { return; } var transformMatrix = transform.localToWorldMatrix; LocalToWorldJob.ScheduleJob(_guid, transformMatrix); }
void CleanUp() { if (_buoyancyType == BuoyancyType.Physical || _buoyancyType == BuoyancyType.PhysicalVoxel) { LocalToWorldJob.Cleanup(_guid); } else { _samplePoints.Dispose(); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var localToWorldJob = new LocalToWorldJob { commandBuffer = _entityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), entityType = GetArchetypeChunkEntityType() }.Schedule(_localToWorldGroup); var translationJob = new TranslationJob().Schedule(_translationQuery, inputDeps); var rotationJob = new RotationJob().Schedule(_rotationQuery, inputDeps); _entityCommandBufferSystem.AddJobHandleForProducer(localToWorldJob); return(JobHandle.CombineDependencies(localToWorldJob, translationJob, rotationJob)); }
private void SetupPhysical() { if (!TryGetComponent(out _rb)) { _rb = gameObject.AddComponent <Rigidbody>(); Debug.LogError($"Buoyancy:Object \"{name}\" had no Rigidbody. Rigidbody has been added."); } _rb.centerOfMass = centerOfMass + _voxelBounds.center; _baseDrag = _rb.drag; _baseAngularDrag = _rb.angularDrag; _velocity = new float3[_voxels.Length]; var archimedesForceMagnitude = WaterDensity * Mathf.Abs(Physics.gravity.y) * volume; _localArchimedesForce = new float3(0, archimedesForceMagnitude, 0) / _voxels.Length; LocalToWorldJob.SetupJob(_guid, _voxels, ref _samplePoints); }
private void FixedUpdate() { var submergedAmount = 0f; switch (_buoyancyType) { case BuoyancyType.PhysicalVoxel: { LocalToWorldJob.CompleteJob(_guid); //Debug.Log("new pass: " + gameObject.name); Physics.autoSyncTransforms = false; for (var i = 0; i < _voxels.Length; i++) { BuoyancyForce(_samplePoints[i], _velocity[i], Heights[i].y + waterLevelOffset, ref submergedAmount, ref _debugInfo[i]); } Physics.SyncTransforms(); Physics.autoSyncTransforms = true; UpdateDrag(submergedAmount); break; } case BuoyancyType.Physical: //LocalToWorldJob.CompleteJob(_guid); BuoyancyForce(Vector3.zero, _velocity[0], Heights[0].y + waterLevelOffset, ref submergedAmount, ref _debugInfo[0]); //UpdateDrag(submergedAmount); break; case BuoyancyType.NonPhysical: break; case BuoyancyType.NonPhysicalVoxel: break; default: throw new ArgumentOutOfRangeException(); } }
private void OnDestroy() { LocalToWorldJob.Cleanup(_guid); }
private void OnDisable() { LocalToWorldJob.Cleanup(_guid); }