|
|
|
|
|
|
public sealed class KeypointLabeler : CameraLabeler |
|
|
|
{ |
|
|
|
internal const float defaultSelfOcclusionDistance = 0.15f; |
|
|
|
const int k_MinTextureWidth = 4; |
|
|
|
// Smaller texture sizes produce assertion failures in the engine
|
|
|
|
const int k_MinTextureWidth = 8; |
|
|
|
|
|
|
|
static ProfilerMarker k_OnEndRenderingMarker = new ProfilerMarker($"KeypointLabeler OnEndRendering"); |
|
|
|
static ProfilerMarker k_OnVisualizeMarker = new ProfilerMarker($"KeypointLabeler OnVisualize"); |
|
|
|
|
|
|
//grab the slice of the list for the current object to assign positions in
|
|
|
|
var checkLocationsSlice = new NativeSlice<float3>(checkLocations, listStart); |
|
|
|
|
|
|
|
var cameraPosition = perceptionCamera.transform.position; |
|
|
|
var cameraforward = perceptionCamera.transform.forward; |
|
|
|
|
|
|
|
// Go through all of the rig keypoints and get their location
|
|
|
|
for (var i = 0; i < activeTemplate.keypoints.Length; i++) |
|
|
|
{ |
|
|
|
|
|
|
var bone = animator.GetBoneTransform(pt.rigLabel); |
|
|
|
if (bone != null) |
|
|
|
{ |
|
|
|
InitKeypoint(bone.position, cachedData, checkLocationsSlice, i, this.selfOcclusionDistance); |
|
|
|
var bonePosition = bone.position; |
|
|
|
var jointSelfOcclusionDistance = JointSelfOcclusionDistance(bone, bonePosition, cameraPosition, cameraforward, this.selfOcclusionDistance); |
|
|
|
InitKeypoint(bonePosition, cachedData, checkLocationsSlice, i, jointSelfOcclusionDistance); |
|
|
|
var cameraPosition = perceptionCamera.transform.position; |
|
|
|
var cameraforward = perceptionCamera.transform.forward; |
|
|
|
|
|
|
|
float jointSelfOcclusionDistance; |
|
|
|
var jointTransform = joint.transform; |
|
|
|
var jointPosition = jointTransform.position; |
|
|
|
float resolvedSelfOcclusionDistance; |
|
|
|
|
|
|
default: |
|
|
|
throw new NotImplementedException("Invalid SelfOcclusionDistanceSource"); |
|
|
|
} |
|
|
|
|
|
|
|
var depthOfJoint = Vector3.Dot(jointPosition - cameraPosition, cameraforward); |
|
|
|
var cameraEffectivePosition = jointPosition - cameraforward * depthOfJoint; |
|
|
|
|
|
|
|
var jointRelativeCameraPosition = jointTransform.InverseTransformPoint(cameraEffectivePosition); |
|
|
|
var jointRelativeCheckPosition = jointRelativeCameraPosition.normalized * resolvedSelfOcclusionDistance; |
|
|
|
var worldSpaceCheckVector = jointTransform.TransformVector(jointRelativeCheckPosition); |
|
|
|
jointSelfOcclusionDistance = worldSpaceCheckVector.magnitude; |
|
|
|
var jointSelfOcclusionDistance = JointSelfOcclusionDistance(joint.transform, jointPosition, cameraPosition, cameraforward, resolvedSelfOcclusionDistance); |
|
|
|
|
|
|
|
InitKeypoint(jointPosition, cachedData, checkLocationsSlice, idx, jointSelfOcclusionDistance); |
|
|
|
} |
|
|
|
|
|
|
}; |
|
|
|
keypointEntries.Add(keypointEntry); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private float JointSelfOcclusionDistance(Transform transform, Vector3 jointPosition, Vector3 cameraPosition, |
|
|
|
Vector3 cameraforward, float configuredSelfOcclusionDistance) |
|
|
|
{ |
|
|
|
var depthOfJoint = Vector3.Dot(jointPosition - cameraPosition, cameraforward); |
|
|
|
var cameraEffectivePosition = jointPosition - cameraforward * depthOfJoint; |
|
|
|
|
|
|
|
var jointRelativeCameraPosition = transform.InverseTransformPoint(cameraEffectivePosition); |
|
|
|
var jointRelativeCheckPosition = jointRelativeCameraPosition.normalized * configuredSelfOcclusionDistance; |
|
|
|
var worldSpaceCheckVector = transform.TransformVector(jointRelativeCheckPosition); |
|
|
|
return worldSpaceCheckVector.magnitude; |
|
|
|
} |
|
|
|
|
|
|
|
private void InitKeypoint(Vector3 position, CachedData cachedData, NativeSlice<float3> checkLocations, int idx, |
|
|
|