Hello,
Im trying to run ScreenToWorldSystem.cs from the tiny example in isolation in a clean empty project but im having some trouble.
it failing on Asert Assert.IsTrue(ePickRoot != Entity.Null); // No root for picking with this id found
/// <summary>
/// Convert screen point to world point
/// </summary>
public static class ScreenToWorldSystem
{
// Camera distance
private const float nearClip = 6.5f;
public static float3 ScreenPointToWorldPoint(World world, float screenPoint)
{
var screenToWorldSystem = world.GetExistingSystem<ScreenToWorld>();
var worldPoint = screenToWorldSystem.ScreenSpaceToWorldSpacePos(screenPoint, nearClip);
return worldPoint;
}
}
public float3 ScreenSpaceToWorldSpace(float2 screenPos, float normalizedZ, ScreenToWorldId id)
{
Entity ePickRoot, ePass;
FindPickRoot(out ePickRoot, out ePass, id);/ !!!!!
if (ePickRoot == Entity.Null)
return new float3(0);
// root and viewport transform
var pass = EntityManager.GetComponentData<RenderPass>(ePass);
float2 pp = InverseViewPortTransform(screenPos, pass);
float4 pp2 = InversePassTransform(new float4(pp, normalizedZ, 1), pass);
// now apply transform for all passes in list as well, if there is one
if (!EntityManager.HasComponent<ScreenToWorldPassList>(ePickRoot)) {
pp2 *= 1.0f / pp2.w; // homogenize, as we drop w here, we need to turn it into w=1
return pp2.xyz;
}
var l = EntityManager.GetBuffer<ScreenToWorldPassList>(ePickRoot);
for (int i = 0; i < l.Length; i++)
{
var lp = EntityManager.GetComponentData<RenderPass>(l[i].pass);
pp2 = InversePassTransform(pp2, lp);
}
pp2 *= 1.0f / pp2.w; // homogenize, as we drop w here, we need to turn it into w=1
return pp2.xyz;
}
protected void FindPickRoot(out Entity eOutPickRoot, out Entity eOutPass, ScreenToWorldId id)
{
var ePickRoot = Entity.Null;
var ePass = Entity.Null;
Entities.ForEach((Entity e, ref ScreenToWorldRoot root) => {
if (root.id == id)
{
Assert.IsTrue(ePickRoot == Entity.Null); // Multiple roots with same pick id found
ePickRoot = e;
ePass = root.pass;
Assert.IsTrue(ePass != Entity.Null);
}
}).Run();
Assert.IsTrue(ePickRoot != Entity.Null); // No root for picking with this id found // !!!!!!!!
eOutPickRoot = ePickRoot;
eOutPass = ePass;
}
InvalidOperationException: Assertion failed.
Unity.Tiny.Rendering.ScreenToWorld.FindPickRoot (Unity.Entities.Entity& eOutPickRoot, Unity.Entities.Entity& eOutPass, Unity.Tiny.Rendering.ScreenToWorldId id) (at Library/PackageCache/com.unity.tiny@0.31.0-preview.24/Unity.Tiny.Rendering/ScreenToWorld.cs:97)
Unity.Tiny.Rendering.ScreenToWorld.ScreenSpaceToWorldSpace (Unity.Mathematics.float2 screenPos, System.Single normalizedZ, Unity.Tiny.Rendering.ScreenToWorldId id) (at Library/PackageCache/com.unity.tiny@0.31.0-preview.24/Unity.Tiny.Rendering/ScreenToWorld.cs:132)
Unity.Tiny.Rendering.ScreenToWorld.ScreenSpaceToWorldSpaceRay (Unity.Mathematics.float2 screenPos, Unity.Mathematics.float3& origin, Unity.Mathematics.float3& direction, Unity.Tiny.Rendering.ScreenToWorldId id) (at Library/PackageCache/com.unity.tiny@0.31.0-preview.24/Unity.Tiny.Rendering/ScreenToWorld.cs:214)
Unity.Tiny.Rendering.ScreenToWorld.ScreenSpaceToWorldSpacePos (Unity.Mathematics.float2 screenPos, System.Single distanceToCamera, Unity.Tiny.Rendering.ScreenToWorldId id) (at Library/PackageCache/com.unity.tiny@0.31.0-preview.24/Unity.Tiny.Rendering/ScreenToWorld.cs:223)
Systems.ScreenToWorldSystem.ScreenPointToWorldPoint (Unity.Entities.World world, System.Single screenPoint) (at Assets/Scripts/Systems/ScreenToWorldSystem.cs:19)
Systems.InputControllerSystem.OnUpdate () (at Assets/Scripts/Systems/InputControllerSystem.cs:28)
Im not sure what im missing to make this work, is there components i need to add to a camera or scene. P
Any help would be appriciated
