Better testscene
This commit is contained in:
@@ -1,34 +1,43 @@
|
||||
-- ============================================================================
|
||||
-- entity_scanner.lua - Scans all entities on interact (Entity.ForEach test)
|
||||
-- ============================================================================
|
||||
-- entity_scanner.lua - Scans all entities on interact
|
||||
-- Tests: Entity.ForEach, Entity.GetPosition, Entity.IsActive, Entity.GetCount,
|
||||
-- Entity.FindByIndex, onInteract
|
||||
-- Entity.FindByIndex, Entity.FindByScriptIndex, Vec3.lerp, Vec3.distanceSq
|
||||
|
||||
function onInteract(self)
|
||||
setStatus("Scanning all entities...")
|
||||
Debug.Log("=== Entity Scan ===")
|
||||
Debug.Log("Total entities: " .. Entity.GetCount())
|
||||
|
||||
local total = Entity.GetCount()
|
||||
Debug.Log("Total entities: " .. total)
|
||||
|
||||
local activeCount = 0
|
||||
local inactiveCount = 0
|
||||
|
||||
Entity.ForEach(function(obj)
|
||||
Entity.ForEach(function(obj, index)
|
||||
local pos = Entity.GetPosition(obj)
|
||||
local active = Entity.IsActive(obj)
|
||||
if active then
|
||||
activeCount = activeCount + 1
|
||||
else
|
||||
inactiveCount = inactiveCount + 1
|
||||
end
|
||||
activeCount = activeCount + 1
|
||||
Debug.Log(" [" .. index .. "] pos="
|
||||
.. pos.x .. "," .. pos.y .. "," .. pos.z
|
||||
.. " active=" .. tostring(Entity.IsActive(obj)))
|
||||
end)
|
||||
|
||||
Debug.Log("Active: " .. activeCount .. " Inactive: " .. inactiveCount)
|
||||
setStatus("Scan: " .. activeCount .. " active, " .. inactiveCount .. " inactive")
|
||||
Debug.Log("Active: " .. activeCount .. " of " .. total)
|
||||
setStatus("Scan: " .. activeCount .. "/" .. total .. " active")
|
||||
|
||||
-- Test FindByIndex
|
||||
local first = Entity.FindByIndex(0)
|
||||
if first then
|
||||
local pos = Entity.GetPosition(first)
|
||||
Debug.Log("Entity 0 at " .. pos.x .. "," .. pos.y .. "," .. pos.z)
|
||||
end
|
||||
|
||||
local byScript = Entity.FindByScriptIndex(0)
|
||||
if byScript then
|
||||
Debug.Log("Found entity using script 0")
|
||||
end
|
||||
|
||||
local a = Vec3.new(0, 0, 0)
|
||||
local b = Vec3.new(10, 20, 30)
|
||||
local mid = Vec3.lerp(a, b, 1/2)
|
||||
Debug.Log("Vec3.lerp midpoint: " .. mid.x .. "," .. mid.y .. "," .. mid.z)
|
||||
|
||||
local dsq = Vec3.distanceSq(a, b)
|
||||
Debug.Log("Vec3.distanceSq: " .. dsq)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user