So,
I tried your library Adam, and i got an error: material.onBeforeRender is not a function.
So I kept going with the following snippet:
let geometry = new BoxGeometry(5, 5, 5);
let mtl = new Nodes.MeshStandardNodeMaterial();
let triplanarMapping = new Nodes.FunctionNode([
// Reference: https://github.com/keijiro/StandardTriplanar
'vec4 triplanarMapping( sampler2D map, vec3 normal, vec3 position, float scale ) {',
// Blending factor of triplanar mapping
' vec3 bf = normalize( abs( normal ) );',
' bf /= dot( bf, vec3( 1.0 ) );',
// Triplanar mapping
' vec2 tx = position.yz * sscale;',
' vec2 ty = position.zx * scale;',
' vec2 tz = position.xy * scale;',
// Base color
' vec4 cx = texture2D(map, tx) * bf.x;',
' vec4 cy = texture2D(map, ty) * bf.y;',
' vec4 cz = texture2D(map, tz) * bf.z;',
' return cx + cy + cz;',
'}'
].join('\n'));
let scale = new Nodes.FloatNode(.02);
let diffuseM = new Nodes.TextureNode(await get_texture("c_diffu"));
let normalM = new Nodes.NormalMapNode(await get_texture("c_nm"))//new Nodes.NormalNode(Nodes.NormalNode.WORLD);
let posNode = new Nodes.PositionNode(Nodes.PositionNode.WORLD);
let triplanarMappingTexture = new Nodes.FunctionCallNode(triplanarMapping, {
map: diffuseM,
normal: new Vector3(4.0, 1.0, 8.5),
position: new Vector3(10.0, 1.0, 0.5),
scale: scale
});
//geometry.computeVertexNormals();
mtl.color.set( triplanarMappingTexture)
const cube = new Mesh(geometry, mtl);
cube.position.set(5, 1, 1)
console.log(geometry, cube)
scene.add(cube);
Unfortunately, while trying so many things I even lost the working triplanar piece of code. Back to point 0.
I even added a typo: sscale and it didn’t noticed the error, which makes me think that the code is never executed.
I tried different things the whole afternoon, I cannot take it anymore.
Could someone chime in and tell me why it doesn’t work please?