Jump to content

loaded models via lua don't get removed or move with parent.


AggrorJorn
 Share

Recommended Posts

I got this script running last weekend but I can't seem to get it working again. I'm using a pivot point that loads all kinds of rooms from a house. The loading goes well but when I delete the house, the rooms are still there. Also, the rooms do not move when I'm moving the gizmo.

 

house.lua:

require("scripts/class")

local class=CreateClass(...)

function class:CreateObject(model)
local object=self.super:CreateObject(model)

self.basement=LoadModel("abstract::matt_house_basement.gmf")
self.basement:SetParent(self.model)

function object:Free(model)
	self.super:Free()
end

end

 

basement.lua:

require("scripts/class")

local class=CreateClass(...)

function class:CreateObject(model)
local object=self.super:CreateObject(model)

object.model:SetCollisionType(COLLISION_SCENE)

function object:Free(model)
	self.super:Free()
end

end

Link to comment
Share on other sites

I believe it should be like that. Your Parent "House" doesn't tell the child to clear, just because you remove it. You must specify..

 

I think.

 

require("scripts/class")

local class=CreateClass(...)

function class:CreateObject(model)
local object=self.super:CreateObject(model)

self.basement=LoadModel("abstract::matt_house_basement.gmf")
self.basement:SetParent(self.model)

function object:Free(model)
               self.basement:Free()
	self.super:Free()
end

end

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

try this:

require("scripts/class")

local class=CreateClass(...)

function class:CreateObject(model)
       local object=self.super:CreateObject(model)

       object.basement=LoadModel("abstract::matt_house_basement.gmf")
       object.basement:SetParent(object.model,0)

       function object:Free(model)
               self.super:Free()
       end

end

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

If you hide a parent does the child get hidden also? If so that could be an issue. These models in the editor have a sphere mesh & body to them. I would think if you had enough of them it "could" produce a loss in fps that wouldn't be needed if you could just hide them. Hence you would need a ton of them, but not sure how many this would produce for him. That model in the editor isn't needed in game, just in the editor to place things. If I'm reading what he's doing right. Maybe not.

Link to comment
Share on other sites

If you hide a parent does the child get hidden also? If so that could be an issue. These models in the editor have a sphere mesh & body to them. I would think if you had enough of them it "could" produce a loss in fps that wouldn't be needed if you could just hide them. Hence you would need a ton of them, but not sure how many this would produce for him. That model in the editor isn't needed in game, just in the editor to place things. If I'm reading what he's doing right. Maybe not.

 

A child hides whenever the parent hides but the parent doesn't hide when the child is hidden.

 

And this is an actual model with its own PHY body, not some primitive being constructed via code that requires a dummy mesh to be used for selection. When the parent/child is hidden so is its phy body.

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

Ah, when I saw

 

self.basement=LoadModel("abstract::matt_house_basement.gmf")

self.basement:SetParent(self.model)

 

 

it looked like he was just loading one part of the room for each editor model.

 

I'm confused as to why would he need to load the gmf in code? Why not just have the gmf be the model he drags into the editor?

Link to comment
Share on other sites

ah.. ok... i was wondering what that statement was about.. ;) at least I hope he isn't using a dummy mesh then loading the all the rooms with lua... :) hopefully that code is the lua script for the actual house model.

 

actually if he is doing it the way i think he is with each model having a common pivot/origin to each other, then it would make loading the extra room models easy... perhaps you could even set up a property dialog to determine which rooms get loaded... that way you could have many different house configurations but only actually have one common script.

 

I'm confused as to why would he need to load the gmf in code? Why not just have the gmf be the model he drags into the editor?

 

well seems like it would be easier to just have the house and basement as one model... but if he was going to expand on that script with like i mentioned with the properties dialog, he could decide what else gets loaded with the main house model...

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

That would be pretty cool. The crappy part about it though is it's pretty static. I wish the settings were more dynamic. I also wish it had a button so we could add things on the fly. For example, if you press the "Add Room" button it adds another settings section for another room to load.

 

I think you might be limited in the placement of the rooms though, or that property box would need to be pretty elaborate to allow to place rooms anywhere.

Link to comment
Share on other sites

That would be pretty cool. The crappy part about it though is it's pretty static. I wish the settings were more dynamic. I also wish it had a button so we could add things on the fly. For example, if you press the "Add Room" button it adds another settings section for another room to load.

 

I think you might be limited in the placement of the rooms though, or that property box would need to be pretty elaborate to allow to place rooms anywhere.

 

yeah at some point the properties box would get a little too unwieldy with all of the options i would guess...

 

but actually, i think there might be an issue with doing it this way... it doesn't appear that the PHY file gets loaded when you load a gmf via a script... hmmm...

 

--EDIT-- ok it does... you just need to set the collisiontype of the child... :)

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

Ah, when I saw

 

self.basement=LoadModel("abstract::matt_house_basement.gmf")

self.basement:SetParent(self.model)

 

 

it looked like he was just loading one part of the room for each editor model.

 

I'm confused as to why would he need to load the gmf in code? Why not just have the gmf be the model he drags into the editor?

I removed all the other rooms for the sake of the topic. I load around 10 rooms in total

 

I work as follow: I have a single pivot point with no further mesh. This pivot is called 'house'. The house loads all the different room of the entire house. Because of the offset from each room, I don't need to position them. Every room can have its own code if needed.

 

I can walk around in the house since every room has a phy file. The pivot itself doesn't have a phy file.

Link to comment
Share on other sites

I get it. So in your modeling program you actually modeled these rooms offset from the origin. I would think allowing to position the rooms in the editor would be more flexible. Is it that big of a pain to get them lined up correctly in the editor? (I meant that as an actual question not like a smartass like it reads :( )

 

You pivot object has a gmf though right? I was under the impression that all those objects needed a gmf even if it was the small sphere. Even the lights have a gmf associated with them. If that's the case then I think a phy file is created automatically when you run the game even if you don't want it.

Link to comment
Share on other sites

I get it. So in your modeling program you actually modeled these rooms offset from the origin. I would think allowing to position the rooms in the editor would be more flexible. Is it that big of a pain to get them lined up correctly in the editor? (I meant that as an actual question not like a smartass like it reads :) )

 

You pivot object has a gmf though right? I was under the impression that all those objects needed a gmf even if it was the small sphere. Even the lights have a gmf associated with them. If that's the case then I think a phy file is created automatically when you run the game even if you don't want it.

I simply copied the road object files and renamed everything. Ofcourse I cleaned the matt and lua file. I build an entire house in 3d max as I can position with very much accuracyg. When I export every single room at the time, the offset is being preserved.

 

Ofcourse I can position every room by hand, but it never got that precise as when I used my current method (believe me: I tried a lot! The problem here is that the walls are made by flip polygons. This allows watching through one side of the wall. Therefore you can't see where the walls are intersecting. It just takes a lot more time.) I can still position every single room separate inside the editor, but because there are so many rooms I want to create some sort of prefab that places every room in correct place.

Link to comment
Share on other sites

interesting aggror... but there's no reason to use an extra object file.

 

just have your entire house model put together with all the rooms... determine where you want a common pivot/origin for all of the room models. export them individually with the offset built in... then in the main house model's script, just add code to load the extra rooms as needed.

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

interesting aggror... but there's no reason to use an extra object file.

 

just have your entire house model put together with all the rooms... determine where you want a common pivot/origin for all of the room models. export them individually with the offset built in... then in the main house model's script, just add code to load the extra rooms as needed.

isn't that the thing I'm already doing? Or do you mean: load for example the basement as the foundation (instead of the pivot), and it that lua file, load all the other rooms?

Link to comment
Share on other sites

Or do you mean: load for example the basement as the foundation (instead of the pivot), and it that lua file, load all the other rooms?

 

yes... thats exactly what i mean... no reason to use a dummy mesh when you already have a perfectly good model mesh.. :) or use the house as the foundation... makes no difference...

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