浏览代码

Make scaling of self-occlusion distance apply in every scenario

/keypoint_self_occlusion
Jon Hogins 4 年前
当前提交
8a57c87c
共有 1 个文件被更改,包括 21 次插入14 次删除
  1. 35
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs

35
com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs


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,

正在加载...
取消
保存