[SOLVED] Setting material.normalMap hides model

Hi, does anybody know why setting material.normalMap results in a hidden model and even causing some WebGL errors?

I’m totally stuck on this issue as I don’t know how to improve graphics with this bug.

In video I just set an already available texture to keep it simple, but I also tested with a “real” normal texture, same issue.

Hmm… I can’t reproduce this issue.

Can you share the model please?

Hey, thanks for testing, yaustar. I made a minimal example now, recreating somewhat the game scene in the video.

Because I load my models as raw data I had to add procedural mesh support to playcanvas-latest.js It’s just like 15 lines of code around line 22978.

		} else if (typeof newValue == "function") {
			// get new mesh from callback
			var mesh = newValue.bind(this)();
			// and instantiate it
			var system = this.system;
			var gd = system.app.graphicsDevice;
			var node = new pc.GraphNode;
			var model = new pc.Model;
			model.graph = node;
			model.meshInstances = [new pc.MeshInstance(node, mesh, data.material)];
			if (system._inTools) {
			  model.generateWireframe();
			}
			this.model = model;
			this.asset = null;
		} else {

IIRC I had layer problems using the procedural mesh examples I found in this forum, so I added the procedural code in library, which integrates nicely with the {.... layers: worldLayer.id], ...}.

I cannot upload .zip files, so here it is: http://killtube.org/downloads/playcanvas/spinning_cube.zip

For testing, you can call test() to load the crowbar model and normalTest() to set a normalMap, which causes the bug.

I really need working procedural meshes, but it seems my implementation does something not quite right… would be epic if somebody could find the bug and then add the correct procedural code to playcanvas upstream aswell. :smiley:

Hmm… It might be worth checking the engine code that creates the primitives (createBox).

I think there are two sets of UVs that need to be generated/created. Don’t quote me on that as it isn’t my area :thinking:

Heh, wow, thanks alot for the createBox hint… I just compared and figured its setting uvs1 and tangents too. The bug was caused by missing tangents :smiley:

Using this code now:

mesh_from_buffers = function(indices, positions, uvs) {
	var normals = pc.calculateNormals(positions, indices);
	var options = {
		normals: normals,
		uvs: uvs,
		uvs1: uvs,
		indices: indices
	};
	if (pc.precalculatedTangents) {
		options.tangents = pc.calculateTangents(positions, normals, uvs, indices);
	}
	var mesh = pc.createMesh(app.graphicsDevice, positions, options);
	return mesh;
}

I dont know what uvs1 is all about yet, but at least it works for me atm. Thanks!

Looks like you’re on an old version of the engine. The latest version doesn’t require tangents. If it finds the mesh doesn’t have tangents, it generates them in the fragment shader. :smiley:

See this release: