Joe Posted July 17, 2014 Share Posted July 17, 2014 I have an error message stating GetTriangleVertex is a nil value. does anyone know what that means? It is listed as GetTriangleCorner or GetTriangleVertex under Surface in the documentation but neither seem to work I have created a "nearest Vertex" Script, based on GetEntityNeighbours.It returns the vector nearest the position stated. Here it is It will be slow with high numbers of vertices GetVertexCallbackTable = nil function WorldGetVertexInAABBDoCallback(entity,extra) local k = entity:GetKeyValue("mining","") local p = entity:GetPosition(true) if k == "true" then local d = {} local v = 1000 local a = 0 local b = 0 local sfc = entity:GetSurface(0) for i = 0,sfc:CountVertices()-1 do local u = sfc:GetVertexPosition(i) local pos = extra - p d[i] = pos:DistanceToPoint(u) end for i = 0,sfc:CountVertices()-1 do for u = sfc:CountVertices()-1,0,-1 do if d[i] <= d[u] then if v > d[i] then a = i v = d[i] end end end end table.insert(GetVertexCallbackTable,a) end end function GetVertex(entity,position) local result local aabb = AABB() local p = entity:GetPosition(true) aabb.min = p - 5 aabb.max = p + 5 aabb:Update() local table = GetVertexCallbackTable GetVertexCallbackTable = {} entity.world:ForEachEntityInAABBDo(aabb,"WorldGetVertexInAABBDoCallback",position) result = GetVertexCallbackTable GetVertexCallbackTable = table return result end Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 17, 2014 Share Posted July 17, 2014 Without code its hard to say, but if you are iterating through vertex index of the triangle, make sure you have the count right for CountTriangles --> 0 to CountTriangles()-1 like shown here: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/surface/surfacegettrianglevertex-r770 as for GetTriangleCorner - i dont see that command listed in the docs Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Joe Posted July 17, 2014 Author Share Posted July 17, 2014 here is the code for i = 0,2 do local v = self.srfc:GetTriangleVertex(self.hitmark,i) local vp = self.srfc:GetVertexPosition(v) local p = self.entity:GetPosition(true) System:Print(vp) System:Print(p) end it is the link in the index under Surface that has the reference to GetTriangleCorner on the website, at least for me. its not on any other part of the website, and it doesn't highlight, but still this should have returned a triangle not nil method self.hitmark refers to a Pick Triangle Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 17, 2014 Share Posted July 17, 2014 Hmmm offhand i would guess that its GetTriangleVertex just because that matched LE2's command - but you never know. You could try a System:Print(self.hitmark) to see what that value actually is... maybe you are picking the value of CountTriangle when GetTriangleVertex is actually indexed from 0 to (CountTriangle-1). edit - Have you tried the example code to see if that works? also, how are you getting the surface? how is self.srfc defined? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Joe Posted July 17, 2014 Author Share Posted July 17, 2014 its come up -1, you are right. Is it normally a simple process with a Pick triangle? It should come back with the triangle integer according to the PickInfo section. this is the pick script w:Pick(b,b + d,pk,3,true) if pk.entity ~= nil then local v = pk.entity:GetKeyValue("mining","") if v == "true" then pk.entity.script.hitmark = pk.triangle pk.entity.script.srfc = pk.surface pk.entity.script.hitnorm = pk.normal System:Print(pk.entity.script.hitmark) end local v = pk.entity:GetKeyValue("hit","") if v == "false" then pk.entity:SetKeyValue("hit","true") end would it be more than one with that radius? - edit end Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 17, 2014 Share Posted July 17, 2014 I would try it with a radius of 0 to see. -edit -- I assume pk has been defined as PickInfo pk = PickInfo() also it might be failing because it doesnt know what to do with pk.entity.script.xxx... try: local pk = PickInfo() ... self.hitmark = pk.triangle self.srfc = pk.surface self.hitnorm = pk.normal then perform the getVertexTriangle as just: pk.srfc:GetVertexTriangle(self.hitmark,i) Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Joe Posted July 17, 2014 Author Share Posted July 17, 2014 I have tried that now but it has no triangle at all now. I will look in to it. Edit Is it possible to find a triangle on a pick entity that is imported? the triangles might not register in the same way, as when i made the pickinfo global and tried the impact on two places the triangle variable stayed at 0. I will try it on a internal model Quote Link to comment Share on other sites More sharing options...
Joe Posted July 17, 2014 Author Share Posted July 17, 2014 there are no triangles on the internal model either in the global pickinfo, although when i counttriangles there are 480 Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 17, 2014 Share Posted July 17, 2014 thanks for sending the model - i will take a look and forward you a script. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted July 17, 2014 Share Posted July 17, 2014 You are correct. This function is not presently exposed to Lua. I am adding it in now. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Joe Posted July 17, 2014 Author Share Posted July 17, 2014 Thank you Josh Quote 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.