When performing a BoundingBox octree query in lua using GetDrawables, drawable’s rotation is not taken into account, which can give inaccurate results depending on the shape of the drawable.
Is there a turnaround for this issue?
Example:
[spoiler][code]
require “LuaScripts/Utilities/Sample”
function Start()
SampleStart()
CreateScene()
SubscribeToEvent(“PostRenderUpdate”, “HandlePostRenderUpdate”)
end
function CreateScene()
scene_ = Scene()
scene_:CreateComponent(“Octree”)
scene_:CreateComponent(“DebugRenderer”)
-- Box1
box1 = scene_:CreateChild("Box1")
box1.position = Vector3(0, 0, 3)
box1.rotation = Quaternion(0, 45, 0)
local boxObject = box1:CreateComponent("StaticModel")
boxObject.model = cache:GetResource("Model", "Models/Box.mdl")
boxObject.material = cache:GetResource("Material", "Materials/StoneEnvMapSmall.xml")
-- Box2
box2 = scene_:CreateChild("Box2")
box2.position = Vector3(0.9, 0, 1.9)
local boxObject = box2:CreateComponent("StaticModel")
boxObject.model = cache:GetResource("Model", "Models/Box.mdl")
boxObject.material = cache:GetResource("Material", "Materials/StoneEnvMapSmall.xml")
-- Camera
cameraNode = Node()
cameraNode.position = Vector3(0, 4, 0)
cameraNode:LookAt(scene_:GetChild("Box1", true))
camera = cameraNode:CreateComponent("Camera")
camera.farClip = 300
renderer:SetViewport(0, Viewport:new(scene_, camera))
-- BoundingBox Octree query
local bbox = box2:GetComponent("StaticModel").worldBoundingBox
local result = scene_:GetComponent("Octree"):GetDrawables(bbox, DRAWABLE_GEOMETRY)
for i =1, table.maxn(result) do print(result[i].node.name) end
end
function HandlePostRenderUpdate(eventType, eventData)
scene_:GetComponent(“DebugRenderer”):AddBoundingBox(box1:GetComponent(“StaticModel”).worldBoundingBox, Color(1, 1, 1))
end
[/code][/spoiler]