Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE)

using System;
using Crest;
using Unity.Collections;
using UnityEngine;

/// <summary>
Expand All @@ -26,13 +28,22 @@ public class OceanSampleDisplacementDemo : MonoBehaviour
public float _minGridSize = 0f;

GameObject[] _markerObjects = new GameObject[3];
Vector3[] _markerPos = new Vector3[3];
Vector3[] _resultDisps = new Vector3[3];
Vector3[] _resultNorms = new Vector3[3];
Vector3[] _resultVels = new Vector3[3];
NativeArray<Vector3> _markerPos;
NativeArray<Vector3> _resultDisps;
NativeArray<Vector3> _resultNorms;
NativeArray<Vector3> _resultVels;

float _samplesRadius = 5f;

private void Start()
{
_markerPos = new NativeArray<Vector3>(3, Allocator.Persistent);
_resultDisps = new NativeArray<Vector3>(3, Allocator.Persistent);
_resultNorms = new NativeArray<Vector3>(3, Allocator.Persistent);
_resultVels = new NativeArray<Vector3>(3, Allocator.Persistent);

}

void Update()
{
if (OceanRenderer.Instance == null)
Expand All @@ -52,7 +63,7 @@ void Update()

var collProvider = OceanRenderer.Instance.CollisionProvider;

var status = collProvider.Query(GetHashCode(), _minGridSize, _markerPos, _resultDisps, _resultNorms, _resultVels);
var status = collProvider.Query(GetHashCode(), _minGridSize, ref _markerPos, ref _resultDisps, ref _resultNorms, ref _resultVels, true);

if (collProvider.RetrieveSucceeded(status))
{
Expand Down
17 changes: 15 additions & 2 deletions crest/Assets/Crest/Crest/Scripts/Collision/CollProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// NOTE: DWP2 depends on this file. Any API changes need to be communicated to the DWP2 authors in advance.

using Unity.Collections;
using UnityEngine;

namespace Crest
Expand All @@ -22,7 +23,12 @@ public interface ICollProvider
/// <param name="o_resultHeights">Float array of water heights at the query positions. Pass null if this information is not required.</param>
/// <param name="o_resultNorms">Water normals at the query positions. Pass null if this information is not required.</param>
/// <param name="o_resultVels">Water surface velocities at the query positions. Pass null if this information is not required.</param>
int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoints, float[] o_resultHeights, Vector3[] o_resultNorms, Vector3[] o_resultVels);
int Query(int i_ownerHash,
float i_minSpatialLength,
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<float> o_resultHeights,
ref NativeArray<Vector3> o_resultNorms,
ref NativeArray<Vector3> o_resultVels);

/// <summary>
/// Query water physical data at a set of points. Pass in null to any out parameters that are not required.
Expand All @@ -33,7 +39,14 @@ public interface ICollProvider
/// <param name="o_resultDisps">Displacement vectors for water surface points that will displace to the XZ coordinates of the query points. Water heights are given by sea level plus the y component of the displacement.</param>
/// <param name="o_resultNorms">Water normals at the query positions. Pass null if this information is not required.</param>
/// <param name="o_resultVels">Water surface velocities at the query positions. Pass null if this information is not required.</param>
int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoints, Vector3[] o_resultDisps, Vector3[] o_resultNorms, Vector3[] o_resultVels);
/// <param name="useNormals"></param>
int Query(int i_ownerHash,
float i_minSpatialLength,
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<Vector3> o_resultDisps,
ref NativeArray<Vector3> o_resultNorms,
ref NativeArray<Vector3> o_resultVels,
bool useNormals);

/// <summary>
/// Check if query results could be retrieved successfully using return code from Query() function
Expand Down
49 changes: 24 additions & 25 deletions crest/Assets/Crest/Crest/Scripts/Collision/CollProviderBakedFFT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class QueryData
/// position data will be created. This will force any running jobs to complete. The jobs will be kicked off in LateUpdate,
/// so this should be called before the kick-off, such as from Update.
/// </summary>
public int RegisterQueryPoints(int ownerHash, Vector3[] queryPoints, int dataToWriteThisFrame)
public int RegisterQueryPoints(int ownerHash,
ref NativeArray<Vector3> queryPoints,
int dataToWriteThisFrame)
{
var numQuads = (queryPoints.Length + 3) / 4;

Expand Down Expand Up @@ -222,7 +224,7 @@ public CollProviderBakedFFT(FFTBakedData data)
}
}

bool RetrieveHeights(int i_ownerHash, float[] o_resultHeights)
bool RetrieveHeights(int i_ownerHash, NativeArray<float> o_resultHeights)
{
// Return data - get segment from finished jobs
if (o_resultHeights != null && _queryDataHeights._segmentRegistryQueriesResults.TryGetValue(i_ownerHash, out var computedQuerySegment))
Expand All @@ -238,7 +240,7 @@ bool RetrieveHeights(int i_ownerHash, float[] o_resultHeights)
return false;
}

bool RetrieveDisps(int i_ownerHash, Vector3[] o_resultDisps)
bool RetrieveDisps(int i_ownerHash, NativeArray<Vector3> o_resultDisps)
{
// Return data - get segment from finished jobs
if (o_resultDisps != null && _queryDataDisps._segmentRegistryQueriesResults.TryGetValue(i_ownerHash, out var computedQuerySegment))
Expand All @@ -258,7 +260,7 @@ bool RetrieveDisps(int i_ownerHash, Vector3[] o_resultDisps)
return false;
}

bool RetrieveNorms(int i_ownerHash, Vector3[] o_resultNorms)
bool RetrieveNorms(int i_ownerHash, NativeArray<Vector3> o_resultNorms)
{
if (o_resultNorms != null && _queryDataNorms._segmentRegistryQueriesResults.TryGetValue(i_ownerHash, out var computedQuerySegment))
{
Expand All @@ -277,7 +279,7 @@ bool RetrieveNorms(int i_ownerHash, Vector3[] o_resultNorms)
return false;
}

bool RetrieveVels(int i_ownerHash, Vector3[] o_resultVels)
bool RetrieveVels(int i_ownerHash, NativeArray<Vector3> o_resultVels)
{
if (o_resultVels != null && _queryDataVels._segmentRegistryQueriesResults.TryGetValue(i_ownerHash, out var computedQuerySegment))
{
Expand All @@ -294,30 +296,28 @@ bool RetrieveVels(int i_ownerHash, Vector3[] o_resultVels)
return false;
}

public int Query(
int i_ownerHash,
public int Query(int i_ownerHash,
float i_minSpatialLength,
Vector3[] i_queryPoints,
float[] o_resultHeights,
Vector3[] o_resultNorms,
Vector3[] o_resultVels
)
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<float> o_resultHeights,
ref NativeArray<Vector3> o_resultNorms,
ref NativeArray<Vector3> o_resultVels)
{
var dataCopiedOutHeights = RetrieveHeights(i_ownerHash, o_resultHeights);
var dataCopiedOutNorms = RetrieveNorms(i_ownerHash, o_resultNorms);
var dataCopiedOutVels = RetrieveVels(i_ownerHash, o_resultVels);

if (o_resultHeights != null)
{
_queryDataHeights.RegisterQueryPoints(i_ownerHash, i_queryPoints, 1 - _dataBeingUsedByJobs);
_queryDataHeights.RegisterQueryPoints(i_ownerHash, ref i_queryPoints, 1 - _dataBeingUsedByJobs);
}
if (o_resultNorms != null)
{
_queryDataNorms.RegisterQueryPoints(i_ownerHash, i_queryPoints, 1 - _dataBeingUsedByJobs);
_queryDataNorms.RegisterQueryPoints(i_ownerHash, ref i_queryPoints, 1 - _dataBeingUsedByJobs);
}
if (o_resultVels != null)
{
_queryDataVels.RegisterQueryPoints(i_ownerHash, i_queryPoints, 1 - _dataBeingUsedByJobs);
_queryDataVels.RegisterQueryPoints(i_ownerHash, ref i_queryPoints, 1 - _dataBeingUsedByJobs);
}

var allCopied = (dataCopiedOutHeights || o_resultHeights == null)
Expand All @@ -327,30 +327,29 @@ Vector3[] o_resultVels
return allCopied ? (int)QueryStatus.Success : (int)QueryStatus.ResultsNotReadyYet;
}

public int Query(
int i_ownerHash,
public int Query(int i_ownerHash,
float i_minSpatialLength,
Vector3[] i_queryPoints,
Vector3[] o_resultDisps,
Vector3[] o_resultNorms,
Vector3[] o_resultVels
)
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<Vector3> o_resultDisps,
ref NativeArray<Vector3> o_resultNorms,
ref NativeArray<Vector3> o_resultVels,
bool useNormals)
{
var dataCopiedOutDisps = RetrieveDisps(i_ownerHash, o_resultDisps);
var dataCopiedOutNorms = RetrieveNorms(i_ownerHash, o_resultNorms);
var dataCopiedOutVels = RetrieveVels(i_ownerHash, o_resultVels);

if (o_resultDisps != null)
{
_queryDataDisps.RegisterQueryPoints(i_ownerHash, i_queryPoints, 1 - _dataBeingUsedByJobs);
_queryDataDisps.RegisterQueryPoints(i_ownerHash, ref i_queryPoints, 1 - _dataBeingUsedByJobs);
}
if (o_resultNorms != null)
{
_queryDataNorms.RegisterQueryPoints(i_ownerHash, i_queryPoints, 1 - _dataBeingUsedByJobs);
_queryDataNorms.RegisterQueryPoints(i_ownerHash, ref i_queryPoints, 1 - _dataBeingUsedByJobs);
}
if (o_resultVels != null)
{
_queryDataVels.RegisterQueryPoints(i_ownerHash, i_queryPoints, 1 - _dataBeingUsedByJobs);
_queryDataVels.RegisterQueryPoints(i_ownerHash, ref i_queryPoints, 1 - _dataBeingUsedByJobs);
}

var allCopied = (dataCopiedOutDisps || o_resultDisps == null)
Expand Down
16 changes: 14 additions & 2 deletions crest/Assets/Crest/Crest/Scripts/Collision/CollProviderNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE)

using Unity.Collections;
using UnityEngine;

namespace Crest
Expand All @@ -11,7 +12,13 @@ namespace Crest
/// </summary>
public class CollProviderNull : ICollProvider
{
public int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoints, Vector3[] o_resultDisps, Vector3[] o_resultNorms, Vector3[] o_resultVels)
public int Query(int i_ownerHash,
float i_minSpatialLength,
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<Vector3> o_resultDisps,
ref NativeArray<Vector3> o_resultNorms,
ref NativeArray<Vector3> o_resultVels,
bool useNormals)
{
if (o_resultDisps != null)
{
Expand Down Expand Up @@ -40,7 +47,12 @@ public int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoi
return 0;
}

public int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoints, float[] o_resultHeights, Vector3[] o_resultNorms, Vector3[] o_resultVels)
public int Query(int i_ownerHash,
float i_minSpatialLength,
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<float> o_resultHeights,
ref NativeArray<Vector3> o_resultNorms,
ref NativeArray<Vector3> o_resultVels)
{
if (o_resultHeights != null)
{
Expand Down
7 changes: 6 additions & 1 deletion crest/Assets/Crest/Crest/Scripts/Collision/FlowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE)

using Unity.Collections;
using UnityEngine;

namespace Crest
Expand All @@ -17,8 +18,12 @@ public interface IFlowProvider
/// <param name="i_ownerHash">Unique ID for calling code. Typically acquired by calling GetHashCode().</param>
/// <param name="i_minSpatialLength">The min spatial length of the object, such as the width of a boat. Useful for filtering out detail when not needed. Set to 0 to get full available detail.</param>
/// <param name="i_queryPoints">The world space points that will be queried.</param>
/// <param name="o_resultFlows"></param>
/// <param name="o_resultVels">Water surface flow velocities at the query positions.</param>
int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoints, Vector3[] o_resultFlows);
int Query(int i_ownerHash,
float i_minSpatialLength,
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<Vector3> o_resultFlows);

/// <summary>
/// Check if query results could be retrieved successfully using return code from Query() function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE)

using Unity.Collections;
using UnityEngine;

namespace Crest
Expand All @@ -11,7 +12,10 @@ namespace Crest
/// </summary>
public class FlowProviderNull : IFlowProvider
{
public int Query(int i_ownerHash, float i_minSpatialLength, Vector3[] i_queryPoints, Vector3[] o_resultFlows)
public int Query(int i_ownerHash,
float i_minSpatialLength,
ref NativeArray<Vector3> i_queryPoints,
ref NativeArray<Vector3> o_resultFlows)
{
if (o_resultFlows != null)
{
Expand Down
Loading