Jump to content

How to show a ring around an object in editor


Roland
 Share

Recommended Posts

I did something similar for waypoints.

Video:

 

 

But it's not a ring actually (it's a 12 connected lines). It's not for selected entity (only for newly created or moved entity). It's for only one entity class (so it works not for all entities on the scene). And it's hiding automatically after some period of time.

 

Code example (for entity-attached lua-script):

 


local class=CreateClass(...)

 

function class:CreateObject(model)

local object=self.super:CreateObject(model)

 

function object:Init()

self.show_markers = 0

 

AddHook("Flip", object.Render)

end

 

function object:Render()

if object.show_markers > 0 then

SetColor(Vec4(1, 1, 0.5, 1))

local pos = EntityPosition(object.model, 1)

local range = 5

 

for i = 1, 12 do

local angle = math.rad((i - 1) * 30)

local dx = math.cos(angle) * range

local dz = math.sin(angle) * range

local pos1 = CameraUnproject(fw.main.camera, Vec3(pos.x + dx, pos.y, pos.z + dz))

angle = math.rad(i * 30)

dx = math.cos(angle) * range

dz = math.sin(angle) * range

local pos2 = CameraUnproject(fw.main.camera, Vec3(pos.x + dx, pos.y, pos.z + dz))

 

if pos1.z >= 0 and pos2.z >= 0 then

DrawLine(pos1.x, pos1.y, pos2.x, pos2.y)

end

end

end

 

SetColor(Vec4(1, 1, 1, 1))

end

 

function object:ReceiveMessage(message,extra)

local values=string.Explode(message,",")

local command = values[1]

if command == "hide_markers" then

self.show_markers = 0

end

end

 

function object:ShowMarkers()

self.show_markers = os.clock () + 1

SendEntityMessage(self.model, "hide_markers", nil, 1000)

end

 

function object:UpdateMatrix()

self:ShowMarkers()

end

 

function object:UnlockKeys()

self:ShowMarkers()

end

 

function object:Free(model)

RemoveHook("Flip", object.Render)

self.super:Free()

end

 

object:Init()

end

 

 

  • Upvote 1
Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...