Jump to content

Procedural Entities...


coldfire
 Share

Recommended Posts

Hello,

 

I've been working on converting an old project of mine to Leadwerks. The project was a procedural building generator. My question is, is it possible to create a point entity that at spawn, generates a model of its own? I figure it may be possible to use the point entity and attach limbs to it, but unfortunately every which way I've tried to accomplish this I have failed with countless engine crashes. Thanks for any advice.

 

Randy

x_coldfire_x.png

AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3

Link to comment
Share on other sites

Hello,

 

I've been working on converting an old project of mine to Leadwerks. The project was a procedural building generator. My question is, is it possible to create a point entity that at spawn, generates a model of its own? I figure it may be possible to use the point entity and attach limbs to it, but unfortunately every which way I've tried to accomplish this I have failed with countless engine crashes. Thanks for any advice.

 

Randy

 

Should be able to do it via Lua Scripting easily enough. In the Spawn function you'd just have it load models and position them. As long as the mass is set to 0 then you won't have to create joints or anything.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Should be able to do it via Lua Scripting easily enough. In the Spawn function you'd just have it load models and position them. As long as the mass is set to 0 then you won't have to create joints or anything.

 

 

Hmm... I didnt think about making it as a model seperate from the entity... I've been trying to replace the entity, and I think thats where most of my problems were coming from. One way to find out though ;) Thanks for the idea niosop.

x_coldfire_x.png

AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3

Link to comment
Share on other sites

From my understanding the entity is a lua table where the model is an LE TModel. You can create/load any number of models and add a variable to the entity assigning your loaded model.

 

entity = base_Entity(model)

 

entity.mycrazyvariablename = LoadModel("abstract::mymodel.gmf")

entity.anothercrazyvariablename = 5

 

 

And now these variables added to the entity table can be used anytime in your entities script

 

 

I think Josh mentioned he might change the naming from entity to object since LE has a TEntity and it can be confusing when we see the word entity because does it mean a TEntity or just a lua variable? It's a lua variable but it can be confusing.

Link to comment
Share on other sites

Alright, finally making some progress. Now I am having a different problem, however.

 

dofile ("Scripts/base.lua")

function Spawn(model)
local entity=base_Spawn(model)
local RootPosition = entity.model:GetPosition(1)
entity.chunk = {}
entity.chunk[0] = CreateCube()
entity.chunk[0]:SetPosition(RootPosition,1)
function entity:Update()
	RootPosition = entity.model:GetPosition(1)
	entity.chunk[0]:SetPosition(RootPosition,1)
end
end	

function Update(world)
if world==world_main then
	local model,entity
	for model,entity in pairs(entitytable) do
		if model.world==world then
			entity:Update()
		end
	end
 end
end

function Cleanup(world)
end

 

The code creates a cube and places it at the position of the point entity and also repositions at update() in the event that it is moved. The problem I am having is that when I delete the entity, the cube still stays. How would I go about cleaning it up after delete?

x_coldfire_x.png

AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3

Link to comment
Share on other sites

Use the Kill function. Example:

 

function Kill(model)
local entity
entity=entitytable[model]
if entity~=nil then
	if entity.tire[0]~=nil then entity.tire[0]:Free() end
	if entity.tire[1]~=nil then entity.tire[1]:Free() end
	if entity.tire[2]~=nil then entity.tire[2]:Free() end
	if entity.tire[3]~=nil then entity.tire[3]:Free() end
end
end

  • Upvote 1
Link to comment
Share on other sites

Use the Kill function. Example:

 

function Kill(model)
local entity
entity=entitytable[model]
if entity~=nil then
	if entity.tire[0]~=nil then entity.tire[0]:Free() end
	if entity.tire[1]~=nil then entity.tire[1]:Free() end
	if entity.tire[2]~=nil then entity.tire[2]:Free() end
	if entity.tire[3]~=nil then entity.tire[3]:Free() end
end
end

 

Ah, thanks again Rick. I was trying to mess with that before, but as you can tell from my leftover lines at the end, I thought the function was Cleanup(), lol. Thank you very much.

 

Edit: Awesome... worked like a charm.

x_coldfire_x.png

AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3

Link to comment
Share on other sites

Another thing you could do is just set the parent of the chunk. Then you won't even have to move the chunk because it will be translated w/ the parent. It will also be destroyed when the parent is (I think).

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Another thing you could do is just set the parent of the chunk. Then you won't even have to move the chunk because it will be translated w/ the parent. It will also be destroyed when the parent is (I think).

 

yes, this is correct.

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

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...