reepblue Posted February 1, 2016 Share Posted February 1, 2016 Hey all. I've been looking all over the api reference and the forums about this, but is there a way to check a surface's surface area (size)? I want to place a model on the wall with a raycast only if the surface is big enough. Thanks. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Brutile Posted February 1, 2016 Share Posted February 1, 2016 Is this what you're looking for? http://www.leadwerks.com/werkspace/page/api-reference/_/surface/surfacegetaabb-r235 Or do you want something that finds the area of just certain faces of the mesh Quote Link to comment Share on other sites More sharing options...
reepblue Posted February 1, 2016 Author Share Posted February 1, 2016 What would I compare it too? My model as an aabb of 0,0,0; 0,0,0 because it's a flat plane that I want to spawn. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Brutile Posted February 1, 2016 Share Posted February 1, 2016 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 Quote Link to comment Share on other sites More sharing options...
reepblue Posted February 1, 2016 Author Share Posted February 1, 2016 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 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Brutile Posted February 1, 2016 Share Posted February 1, 2016 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? Quote Link to comment Share on other sites More sharing options...
reepblue Posted February 1, 2016 Author Share Posted February 1, 2016 - It can only be placed on CSG - It will always be one model (A flat plane which is 96x96cm) Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Brutile Posted February 1, 2016 Share Posted February 1, 2016 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) Quote Link to comment Share on other sites More sharing options...
reepblue Posted February 1, 2016 Author Share Posted February 1, 2016 Strangely enough, it ether works too good or not enough. I mostly want to fix these cases. Above more or less solved the "If I shoot too close to the corner." issue. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Brutile Posted February 1, 2016 Share Posted February 1, 2016 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. Quote Link to comment Share on other sites More sharing options...
Brutile Posted February 1, 2016 Share Posted February 1, 2016 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. 1 Quote Link to comment Share on other sites More sharing options...
reepblue Posted February 1, 2016 Author Share Posted February 1, 2016 Thanks Burtle, I really don't see much of a problem if I just keep it CSG only. Really, thanks for your help and helping very quickly. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
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.