Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sdk7 raycast-result support for non-sdk7 entity colliders #5986

Merged
merged 4 commits into from
Nov 30, 2023
Merged
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 @@ -210,21 +210,32 @@ private Ray CreateRay(IParcelScene scene, IDCLEntity entity, PBRaycast model)

private RaycastHit CreateSDKRaycastHit(IParcelScene scene, PBRaycast model, UnityEngine.RaycastHit unityRaycastHit, KeyValuePair<IDCLEntity, uint>? hitEntity, Vector3 globalOrigin)
{
if (hitEntity == null) return null;

// TODO: figure out how we can cache or pool this hit instance to reduce allocations.
// since is part of a protobuf message it life span is uncertain, it could be disposed
// after message is sent to the scene or dropped for a new message
RaycastHit hit = new RaycastHit();
IDCLEntity entity = hitEntity.Value.Key;
uint collisionMask = hitEntity.Value.Value;

// hitEntity has to be evaluated since 'Default' layer represents a combination of ClPointer
// and ClPhysics, and 'SDKCustomLayer' layer represents 8 different SDK layers: ClCustom1~8
if ((model.GetCollisionMask() & collisionMask) == 0)
RaycastHit hit = null;
uint modelCollisionLayerMask = model.GetCollisionMask();

if (hitEntity != null) // SDK7 entity, otherwise the ray hit an SDK6 entity
{
// TODO: figure out how we can cache or pool this hit instance to reduce allocations.
// since is part of a protobuf message it life span is uncertain, it could be disposed
// after message is sent to the scene or dropped for a new message
IDCLEntity entity = hitEntity.Value.Key;
uint collisionMask = hitEntity.Value.Value;

// hitEntity has to be evaluated since 'Default' layer represents a combination of ClPointer
// and ClPhysics, and 'SDKCustomLayer' layer represents 8 different SDK layers: ClCustom1~8
if ((modelCollisionLayerMask & collisionMask) == 0)
return null;

hit = new RaycastHit();
hit.EntityId = (uint)entity.entityId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be simplified to

hit = new RaycastHit { EntityId = (uint)entity.entityId };

}
else if ((!scene.isPersistent && !scene.isPortableExperience)
|| (modelCollisionLayerMask & (int)ColliderLayer.ClPhysics) == 0) // 'Physics' layer for non-sdk7 colliders
{
return null;
}

hit.EntityId = (uint)entity.entityId;
hit ??= new RaycastHit();
hit.MeshName = unityRaycastHit.collider.name;
hit.Length = unityRaycastHit.distance;
hit.GlobalOrigin = globalOrigin;
Expand Down
Loading