a few of us over on the scripting forum were discussing dynamic placement of items and hit on something i’m having trouble understanding. the goal is to spawn an item object onto an invisible object placeable. this seems to work for some, but for me it doesn’t [the item ends up on the ground ; i.e., x and y are respected, z isn’t].
i’ve spent quite a bit of time testing this out, starting w/the ‘invisible object’ placeable, placed static in the area. i create the item either at or above the invisible object’s location by using one of two pull-chains i’ve placed for that purpose to initiate the spawn. i then ran the module several times, changing only the ‘invisible object’ placeable’s appearance type to something else each time.
on my system, to get a sword to stay put at the placeable’s location, it seems like the following conditions must be met :
- the placeable must have visible ‘material’ vertices. a placeable composed only of emitters [e.g. shaft of light, ground fog] won’t work, regardless of whether it’s static or not. since the ‘invisible object’ placeable doesn’t have ‘material’, it doesn’t work either.
- the ‘material’ vertices must be at the spawn-in location. if the ‘material’ part of the placeable is elsewhere [e.g., ‘sheet of paper’ model], it won’t work.
you guys who work with models all the time, could one of you explain the reason behind the behaviour i’m seeing and why i’m not able to get an item to spawn on an invisible object ?
I’m puzzled - how come items are spawning on invisible objects for me, but not for you? Did you try the debug mode script I posted in the other thread?
…but, yes, I’d welcome any input from modellers here, too…
I you are using the InvObj placeable (plc_u02 at line 157 in placeables.2da) that might be part of the issue. The model is a simple non-rendering rectangle so it does occupy a physical space. However, the corresponding pwk file contains only a use node. There is no walkmesh associated with it; therefore, if my memory serves, anything placed on top of it will drop to the Z-height of the ground dummy node (node U02_ground).
It is possible the you would have to spawn the object at the center of the invisible placeable so that it sits on top of it. This is because, if memory serves, in the absence of a pwk for a placeable, the engine will create a single vertex at the center of the placeable object to denote the Z-height surface. Whereas, when the pwk is present, the engine uses the topmost faces of the geometry to set a Z-height surface.
Keep in mind, I may be totally off base here as its been ages since I’ve even given such matters a single thought.
1 Like
aha ! walkmesh !
yes, that’s the placeable i’m using.
your description of the centering would also explain why some other placeables [‘sheet of paper’, for example] also allow the item to fall to the ground even though they have ‘material’ vertices.
i don’t suppose there’s a straightforward and foolproof way to get the exact location of the centre of one of these things ?? or find that vertex you’re talking about ?
@Proleric i’m not sure. the following possibilities come to mind –
1- it’s a vertex thing, along the lines of what pstemarie’s describing.
2- i didn’t run it in debug mode and that broke it.
3- version differences [i’m running oob nwn platinum fully patched to 1.69 on windows 7, but i know some run the gog version whilst others run the 1.69 ‘critical rebuild’, and there are differences between those versions in other areas, so maybe this as well ? and then there are windows/mac differences that might also contribute… ]
4- timing [my machine, being over 10 y.o. now, isn’t blazingly top spec…]
5- another bizarre and fully teeth-gnashing unresolved issue having to do w/the cantankerous gremlin who lives in my graphics processor.
although putting everything together in one line has caused problems for me in the past [so i tend to break my code into smaller nwn-digestible pieces], copying/pasting your succinct one-liner works absolutely fine for me too – except for the cases i mentioned above. so whatever is happening, it certainly doesn’t seem to be dependent on coding.
one thing i noticed is that the placeable model does seem to have something to do w/where the item ends up, since spawning an item over the placeable usually results in the item being placed on top of it, yet spawning it at the placeable’s exact location may yield differing results. [try using the ‘mushroom 1’ appearance type, for example.]
in any case, if it turns out my ‘vertices’ idea is daft, i’m going w/possibility #5.
The center for BioWare placeables usually (as in 90% of the time) correlates to x0 y0. For the Z-height it typically uses the z-height of the faces. This may also be another area where smoothing groups come into play. For example, if you make a simple cube in 3dsMax, select all the faces, then run auto smooth, you’ll end up with six smoothing groups - one for each face. I believe the top face of the rendered cube would then be used to set the z-height of the model.
Furthermore, when _Six and I were experimenting with pwk on some items, the engine seemed easily capable of processing 3D geometry for the walkmesh. However, if you look at BioWare’s models, they all use a flat 2D plain. I also vaguely recall something about changing the model type for the placeable from “character” to “tile” - maybe that was how we got the engine to recognize the 3D pwk geometry.
So to answer your question, the InvObj is most likely using the U02_ground node to set the z-height of anything placed on top of it that isn’t set to the same x and y coordinates.
@xorbaxian sounds like Pstemarie’s on the money, in which case I’d expect my script to work for you on an invisible object.
I’ve now confirmed that it works in a regular script as well as in Debug Mode.
My builds are the original Diamond Edition CD plus 1.69 Critical Rebuild, EE Beamdog version and EE Steam versions. Works in all cases. Can’t imagine that your build, hardware or graphics card would make a difference?
well, i admit, i was grasping at straws. regardless of what the cause is, it quite clearly doesn’t work w/models that have no walkmesh [see the screenie below, you may have to click the image to get the enlarged version].
in this test module i’ve got 4 placeables on the left [including ‘invisible object’ on the far left] that don’t have walkmesh. you can see here [clearly i hope] that the swords are on the grass, not at the bases of the placeables [which are 2 metres in the air]. the 4 models on the right have the swords at the bases of the placeables.
if i understood @Pstemarie correctly [which isn’t 100% since i’m not a modeler], the ‘invisible object’ placeable doesn’t have a walkmesh so it can’t support items. otoh, if i didn’t, then perhaps there’s something wonky w/my install, but most likely i’ve done something wrong…
if you’d like to try out the demo mod i put together to test this all out, you can download it here. i’m willing to admit i’ve done something silly, but damned if i know what.
Yes, you understood me correctly - somewhat. For a placeable with non-rendering geometry (such as the InvObj which has a rectabgle), no walkmesh = no supporting items or other placeables - it just collapses to the z-height of the “ground” node. However, if the placeable has a rendering geometry, it will allow items/placeables to be placed on top of it.
I tested this theory by first trying to spawn items on top of plc_U02 (InvObj). Then I made a copy of plc_U02 and changed the rectangle to render (open in a txt editor and change the line render 0 to render 1). I was then able to spawn items on top of it. However, the placeable was no longer invisible.
@xorbaxian well this is very strange. Creating an item at an invisible object works for me in every module I try except yours, including a vanilla module. With your module, for some reason, it doesn’t work, even if I make a new area.
Hmm. My install is NWN Gold with HotU added, patched to v1.69. If I try to place or spawn an item/placeable on top of an invisible object, it drops to the ground and cannot be elevated.
Proleric, if you are using InvObj (plc_U02) can you check the pwk model and see if it has only a use node?
The pwk only has a use node.
Another strange discovery. The behaviour depends on the tileset!
In xorbaxian’s test module, if you make a Castle Interior area, copy-and-paste the entire contents of area001 there, reset the placeable heights above floor level again, and start the module there, you should see swords floating in the air, on both the “at” and “above” invisible objects!
So far, it doesn’t seem to work in city exterior or microset, but does work in castle interior, desert & tropical. Go figure!
At any rate, spawning on an invisible object doesn’t seem to be reliable enough to recommend.
Another suggestion - if you add the item model to placeables.2da, you can paint it as a placeable with the plot flag set, adjust the height as desired, and place the corresponding item in inventory. The OnUsed script can then spawn the item in the player’s inventory and delete the placeable.
ActionGiveItem(GetFirstItemInInventory(), GetLastUsedBy());
SetPlotFlag(OBJECT_SELF, FALSE);
ActionDoCommand(DestroyObject(OBJECT_SELF));
In CEP, at least, most of the item models are available as placeables anyway, as a handful of models are used to represent the entire spectrum of items.
1 Like
I was using the Microset for testing. This would lead me to think that something in the SET files is different.
if you add the item model to placeables.2da, you can paint it as a placeable with the plot flag set, adjust the height as desired, and place the corresponding item in inventory.
this is a briliant idea !
thanks !