Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:
Isaac wrote:
Eburt wrote:Is there a way to "flip" an object when spawning it? In other words, I want the facing to be the same, but the actual orientation of the mesh to be pointing the opposite direction. An analogy might be the "flip horizontal" or "flip vertical" functions in most image editors (where changing facing would be analogous to rotating 90 degrees).

Thanks for any help anyone can provide.
If spawning via script, set the desired direction with the facing parameter to the spawn function; if spawning via spawner, position the spawner to point in the intended direction.
1. Rotating 180 degrees is not the same thing as flipping.
2. Eburt specifically said that they do not want the facing to change.

The answer is no, you can't. You can rotate models in their asset definiton, and you can rotate the entire GameObject with the various versions of setWorldRotation(), but there is no way to flip anything since that is a change in the actual shape of the mesh; there's a reason "flip" is separated from rotation options in image/model editors. Try to mirror your keyboard around one axis IRL, it's impossible. You would have to make a separate, flipped version of the mesh.
Oh that...
Well... one can open the model from the asset pack, use the gmt, select the root node, then set the scale to -1, and rotate the model 180° along the X axis; but unfortunately, the GMT [version 1] cannot flip the 'surface normals'... which would mean that the outside surface of the model would be its inside ~like an inside-out shirt.

You could save the model as an OBJ file and use another tool [like Blender] to flip the "surface normals" and save the obj file and open it in GMT again, and then save it as .model; and define a copy of the object (with suitable name), and use the new model in the defined object's model component.

It is rather involved, and offhand, I'm not sure about the licensing for the asset pack; technically it's altered, but effectively it's the same model and would be used in a Grimrock mod.

*** Hang on... Re-reading a second time: If you want only to make the model turned around 180°... Then just open it in the GMT, and rotate the root node 180°, and save it. Use that as the model, in the object def.
Last edited by Isaac on Sun Feb 15, 2015 5:13 am, edited 1 time in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

You would be much better off just using your 3d model editor's "Mirror" functionality. This is literally the purpose of it. Inverting the scale not only requires recalculating normals, but even after doing so, is likely to leave you with a model that doesn't get lit properly.

(And if you're using Blender, why would you want to involve GMT at all now that there's a plugin for Grimrock import/export?)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:You would be much better off just using your 3d model editor's "Mirror" functionality. This is literally the purpose of it. Inverting the scale not only requires recalculating normals, but even after doing so, is likely to leave you with a model that doesn't get lit properly.

(And if you're using Blender, why would you want to involve GMT at all now that there's a plugin for Grimrock import/export?)
The original point was not to use an editor if possible; but the GMT cannot handle the normal flip. :(

Indeed, if Blender is an option, then one can do just about anything they could want to the model. 8-)
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Ask a simple question, get a simple answer

Post by Eburt »

Isaac & minmay,

Thanks for the assistance. I had thought of editing the mesh itself, but this seems clunky and has several disadvantages associated. Further, I'm fairly certain that this is used in the base game. The most obvious example is the "swipe" meshes used in attack animations. If you look at the horizontal or thrust animations, they change (flip about the horizontal) depending on which position the attacking character is. Yet, thanks to the newest version of the asset pack, I can confirm that there is only a single model. How is this possible without some sort of flip function?

Thanks again!
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Eburt wrote:Isaac & minmay,

Thanks for the assistance. I had thought of editing the mesh itself, but this seems clunky and has several disadvantages associated. Further, I'm fairly certain that this is used in the base game. The most obvious example is the "swipe" meshes used in attack animations. If you look at the horizontal or thrust animations, they change (flip about the horizontal) depending on which position the attacking character is. Yet, thanks to the newest version of the asset pack, I can confirm that there is only a single model. How is this possible without some sort of flip function?

Thanks again!
I haven't looked, but it could very easily be a hard-coded behavior done specifically for that effect.

*Is what you want that the model should be a mirror copy?
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Ask a simple question, get a simple answer

Post by Eburt »

I haven't looked, but it could very easily be a hard-coded behavior done specifically for that effect.

*Is what you want that the model should be a mirror copy?
Yes, it is possible that this is hard-coded, but I find that hard to believe, given how complicated that sort of behavior would actually be. Why wouldn't it be set as a general function if the devs went to the effort of developing it? It could also be an animation that instantly flips the object (or starts from a frame when it is flipped) but I'm not familiar enough with model and animation files to test this myself. Anyone with some experience want to take a look?

But yes, I want to mirror the model which is spawned. This is what I meant by "flip".
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Actually, I have to partially retract my previous post.

It looks like setWorldRotation() gives you freedom to set the object's entire transformation matrix. Demonstration. So you can, in fact, do full scale transformations, and you can use negative scale to "flip" objects. The problem is that this form of "flipping" does not alter the normals and they will be wrong as a result. Using a double-sided material does not resolve this issue because the lighting will still be screwed up.

This may be how swipes are flipped, since the material is double-sided and doesn't care about lighting. Doing a simple scale transform is certainly easier to implement than "real" mirroring.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Ask a simple question, get a simple answer

Post by Eburt »

Thanks guys! This is more than good enough for what I'm trying to achieve.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Oh god, please don't actually do that. It looks absolutely terrible unless your material is both double-sided and doesn't use lighting (and double-sided also causes a performance hit so you don't want to use it unless your material actually is being seen from both sides).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Ask a simple question, get a simple answer

Post by Eburt »

minmay wrote:Oh god, please don't actually do that. It looks absolutely terrible unless your material is both double-sided and doesn't use lighting (and double-sided also causes a performance hit so you don't want to use it unless your material actually is being seen from both sides).
I'm using the model as an emitterMesh, so this works fine. I could care less about the material (for now). Thanks for the caution though!
Post Reply