Jump to content

Looking for tips on using opacityTexture (or what I should actually be doing)


davimusprime
 Share

Recommended Posts

I'm working on a batting helmet customizer. The user chooses a style and then colors/finishes for the sections of the style. With all of the style and color options available I decided it would be best to let babylon color the model instead of loading a bunch of textures whenever a color/style was changed. So, my idea was to take the original model in the scene, make it the "base" color then clone it, change its color to the secondary color and apply the opacityTexture to crop out the style where I want it.

let original = this.scene.getMeshByName(name);
let clone = original.clone(name + 'clone',original.parent);

clone.material = original.material.clone(original.material.name+'clone');
(<BABYLON.StandardMaterial>clone.material).diffuseColor = BABYLON.Color3.Green();

let task = loader.addTextureTask('opacity','assets/textures/opacity.png');
task.onSuccess = (t) => {
	console.log(t);
	(<BABYLON.StandardMaterial>clone.material).opacityTexture = t.texture;
	clone.position.y = 0.003;
};

At first, this didn't appear to do anything, but if I offset the clone just a tiny bit there was actually some transparency stuff happening. Sadly, it wasn't transparent where it was supposed to be and it seemed to only be able to go transparent along vectors.

sample1.jpg.7380c66df1887e5e297c3c4529df4bd3.jpg

We used this approach using three js (and alphaMap instead of opacityTexture) with better results but the application is just too cumbersome on machines and babylon seems, at least in theory, to have better performance. helmets.custom.rawlings.com

Any tips, suggestions, or other routes I should take?

Thanks,

David

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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...