Jump to content

Recommended Posts

Posted

Oh, okay. I didn't fully understand what you are doing. So by my understanding, AABB is only calculated if an object is in the world. That's why you're getting 0,0,0; 0,0,0

Posted

Here is my code snippet. What value(s) would be best as each brush can have different dimentions. How would I go and say "If this face is bigger than 96cm x 96cm, then allow placement." ?

 

if pickinfo.surface~=nil then

 --Print out the surface AABB
 local v1 = pickinfo.surface:GetAABB()
 --local v2 = c:GetAABB(Entity.LocalAABB)
 v1:Update()
 --v2:Update()
 System:Print("Surface ")
 System:Print(v1)
 --System:Print("Cyclone ")
 --System:Print(v2)
 if v1.min.y > 1 then
  System:Print("!!!SUCESSFUL PLACEMENT!!!")
  c = tolua.cast(c,"Model")
  c:SetPosition(pickinfo.position)
  c:SetParent(pickinfo.entity)
  c:AlignToVector(pickinfo.normal)
  c:SetScript("Scripts/Objects/Cyclone/Cyclone.lua",false)
  c.script:SetPushDir(pickinfo.normal.x,pickinfo.normal.y,pickinfo.normal.z)
  c.script:SetStartOpen()
  c.script:Start()
  self.LastCyclone = c
 end
end

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Posted

What are the assumptions being made? Are all the surfaces square? Are the surfaces CSG? or does it need to check for any possible surface?

 

Edit: And what about the model being placed? Is that just a flat plane, or can this be a complex object?

Posted

This code will do a basic job of doing what you want, but it has limitations.

 

local hitPos = pickInfo.position
local surface = pickInfo.surface
local canPlace = true

for v = 0, surface:CountVertices() - 1 do
local vertPos = surface:GetVertexPosition(v)

if hitPos:DistanceToPoint(vertPos) < (0.96 / 2) then
 canPlace = false
end
end

print(canPlace)

Posted

I have an idea. I'll put into pseudo code, then I'll try to figure it out in code.

 

for all connecting vertices,

find the closest point along that line to the hit point.

If the distance between that point and the hit point is < 96 / 2 then don't spawn object.

 

Edit: We would also need to ignore the line that goes diagonally.

Posted

I figured it out, but it's quite slow.

 

local hitPos = pickInfo.position
local surface = pickInfo.surface
local canPlace = true

for v1 = 0, surface:CountVertices() - 1 do
local vertPos1 = surface:GetVertexPosition(v1)
for v2 = 0, surface:CountVertices() - 1 do
if v1 ~= v2 then
 local vertPos2 = surface:GetVertexPosition(v2)
 if (vertPos1.x == vertPos2.x and vertPos1.y == vertPos2.y)
 or (vertPos1.x == vertPos2.x and vertPos1.z == vertPos2.z)
 or (vertPos1.y == vertPos2.y and vertPos1.z == vertPos2.z) then
 local closestPoint = self:ClosestPointOnLine(vertPos1, vertPos2, hitPos)

 if hitPos:DistanceToPoint(closestPoint) < (0.96 / 2) then
 canPlace = false
 end
 end
end
end
end

if canPlace == true then
local bulletDecal = Decal:Create(self.bulletDecalMaterial)
bulletDecal:SetPosition(pickInfo.position, true)
bulletDecal:AlignToVector(pickInfo.normal * -1)
bulletDecal:SetScale(Vec3(0.1, 0.1, 1))
bulletDecal:SetParent(pickInfo.entity)
end

 

function Script:ClosestPointOnLine(vA, vB, vPoint)
local vVector1 = vPoint - vA
local vVector2 = (vB - vA):Normalize()

local d = vA:DistanceToPoint(vB)
local t = vVector2:Dot(vVector1)

if t <= 0 then
return vA
end
if t >= d then
return vB
end

local vVector3 = vVector2 * t
local vClosestPoint = vA + vVector3

return vClosestPoint
end

 

Edit: This is slow because somehow the vertex count on a CSG cube is 128. WTF?

 

Edit: It seems like the engine is combining CSG meshes with the same texture to save draw calls. This is causing the above code to be slow. PickInfo.face.surface would solve this issue, but it doesn't seem to work.

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...