Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Changing "Advanced Texture" map of 3D Model in runtime

A topic by Ubivis created Jan 15, 2016 Views: 1,115 Replies: 9
Viewing posts 1 to 10

Hi all,

I'm experimenting with 3D Models in Superpowers at the moment and do hope that someone can help me.

I have a sweet little model, which loads up nicely. As I have several textures for that model, I created different Maps in "Advances Textures".


While updating the Map-Field in the Model Windows is working fine, I absolutely can't find a solution on how to change the Map in runtime (I tried to find something in the documentation, but all tries (like these:

if (Sup.Input.isKeyDown("1")) this.actor.tileMapRenderer.setTileSet("Adventurer");
if (Sup.Input.isKeyDown("1")) this.actor.tileMapRenderer.setTileMap("Adventurer");
if (Sup.Input.isKeyDown("1")) this.actor.modelRenderer.setModel("Adventurer");

Did not work at all.

Anyone has an idea? I feel a bit lost at the moment :(

Moderator

Hello!

First the tileMapRenderer is completely unrelated to the model. It's a renderer to be used with a Tile Map asset.
Then, there is currently no easy way to change the map on a model at runtime. You could do it with a Shader but that's a bit a work and there is no documentation on that yet so... Not sure what I should suggest you.

(1 edit)

Thanks Bilou84,

I guessed, that it is wrong, I just wanted to show that I tried to find a solution :)

I am currently trying to find a workaround using the DOM and THREE plugins, but still no big success (it is throwing errors:

Uncaught TypeError: Cannot read property 'mesh' of undefinedCharacterBehavior.update @ Game.ts:13Behavior.update @ components.js:24Actor.update @ SupEngine.js:36602(anonymous function) @ SupEngine.js:36932GameInstance.update @ SupEngine.js:36932GameInstance.tick @ SupEngine.js:36900Player.tick @ SupRuntime.js:1657

[object%20Object]:1 GET http://www.ubiville.de:4238/systems/game/[object%20Object] 404 (Not Found)

)


from this code:

var tmpActor: any = this.actor;

if (Sup.Input.isKeyDown("1"))

{

var tmpSprite: any = Sup.get("Assets/Skins/Adventurer", Sup.Sprite);

var texture = THREE.ImageUtils.loadTexture( tmpSprite );

var material = new THREE.MeshNormalMaterial({ map: texture });

tmpActor.__inner.threeobject.mesh.material = material;

tmpActor.__inner.threeobject.mesh.material.needsUpdate = true;

}



But I will keep on trying and hope that at some point, it will be accessible from Superpowers itself.

That it is possible,

i was wondering the same thing. Thank you for posting here. I hope that sp will support texture changing during runtime at some point

Moderator (1 edit) (+1)

Okay, I found a workaround for now!

let renderer = (this.actor.spriteRenderer as any).__inner;
renderer.material.map = renderer.asset.textures["blue"];
renderer.material.needsUpdate = true;

Where "blue" should be the name of your map. Also note this probably won't work if your maps doesn't have the same size.

EDIT: spriteRenderer should be modelRenderer if you are working with a model. I didn't read your question carefully enough, sorry '^^

Nice, thank you. Unfortunately, does not work for me: Uncaught TypeError: Cannot read property '__inner' of undefined


But I will keep trying :)

Moderator

This mean that your actor doesn't have a sprite renderer with a sprite on it.

(2 edits)

Thanks to be so helpful bilou84.

Got that one error resolved but now comes up the next... do you mind having a quick look? Feel a little bit lost here :(

http://www.ubiville.de:4237/project/?project=UzbQ


Tried several ways to work it out:

- added a sprite with the texture

- uploaded the texture directly into "advanced textures"

everytime a new error that comes up :(


At the moment, no error comes up, but also no texture updated.

Moderator

Okay, it's my mistake. My example was for a spriteRenderer when you were trying to do your stuff with a modelRenderer.

I edited my post with the correction ;)

(+1)

Thanks for helping, works like a charm ;)