My three.js wasn’t up-to-date, now i can see both textures, but they are both on the first uvCoords.
"use strict";
import * as THREE from '../../build/three.module.js';
// globals
var BATCHES = [];
var SCENE = null;
var RENDERER = null;
var CAMERA = null;
var DUMMY = null;
var SUN = null;
var MAP = null;
var LIGHTMAP = null;
function CreatePhongMaterial(color, opacity, wireframe, map, lightMap)
{
const obj = {
color: color,
shininess: 2,
emissive: 0xffffffff,
emissiveIntensity: .5,
transparent: (opacity < 1),
opacity: opacity,
wireframe: wireframe,
map: map,
lightMap: lightMap
};
return new THREE.MeshPhongMaterial(obj);
};
function main()
{
console.log("INIT APP");
//Create a WebGLRenderer
SCENE = new THREE.Scene();
CAMERA = new THREE.PerspectiveCamera(90, 800 / 600, 0.1, 10000);
RENDERER = new THREE.WebGLRenderer();
RENDERER.setSize(480, 320);
RENDERER.domElement.style.width = '100%';
RENDERER.domElement.style.height = '100%';
document.getElementById("container").appendChild(RENDERER.domElement);
// world is z-up based
CAMERA.position.x = 16;
CAMERA.position.z = 64;
CAMERA.position.y = 8;
//camera.rotateX(Math.PI / 4);
//turn on shadows in the renderer
//RENDERER.shadowMap.enabled = true;
//RENDERER.shadowMap.type = THREE.PCFSoftShadowMap;
//RENDERER.setClearColor(0x000000, 1);
// sun
SUN = new THREE.DirectionalLight(0xffffff, 1);
SUN.position.set(0, 0, 1000);
SCENE.add(SUN);
// create the dummy
const geometry = new THREE.BoxGeometry(16, 16, 16);
const material = CreatePhongMaterial(0xffffffff, 1, false, null, null);
DUMMY = new THREE.Mesh(geometry, material);
//SCENE.add(DUMMY);
// create a test object for lightmapping
MAP = new THREE.TextureLoader().load( "./textures/test.jpg" );
MAP.wrapS = THREE.RepeatWrapping;
MAP.wrapT = THREE.RepeatWrapping;
LIGHTMAP = new THREE.TextureLoader().load( "./textures/lightmap.jpg" );
LIGHTMAP.wrapS = THREE.RepeatWrapping;
LIGHTMAP.wrapT = THREE.RepeatWrapping;
const obj = {
shininess: 0,
transparent: false,
opacity: 1,
map: MAP,
lightMap: LIGHTMAP
};
const material2 = new THREE.MeshPhongMaterial(obj);
const indexBuffer = [
0, 1, 2,
0, 2, 3,
1, 4, 5,
1, 5, 2
];
const vertBuffer = new Float32Array([
0 , 0 , 0 ,
16, 0 , 0,
16, 16, 0,
0 , 16, 0 ,
32, 0 , 0 ,
32, 16, 0
]);
const uvTex = new Float32Array([
0 , 0 ,
1 , 0 ,
1 , 1 ,
0 , 1 ,
2 , 0 ,
2 , 1
]);
const uvLm = new Float32Array([
0 , 0 ,
.5, 0 ,
.5,.5 ,
0 ,.5 ,
1 , 0 ,
1 ,.5
]);
const geometry2 = new THREE.BufferGeometry();
geometry2.setAttribute('position', new THREE.BufferAttribute(vertBuffer, 3));
geometry2.setAttribute('uv', new THREE.BufferAttribute(uvTex, 2));
geometry2.setAttribute('uv1', new THREE.BufferAttribute(uvLm, 2));
geometry2.setIndex( indexBuffer );
geometry2.computeVertexNormals();
console.log( geometry2.attributes );
const mesh = new THREE.Mesh(geometry2, material2);
SCENE.add(mesh);
// start video routine
requestAnimationFrame(VideoRoutine);
}
main();
function exit()
{
//DUMMY.mesh.dispose();
DUMMY.geometry.dispose();
DUMMY.material.dispose();
console.log("VRAM CLEANED");
console.log("CLOSE APP");
}
window.onunload = exit;
// keyboard
const K = new Uint8ClampedArray(256);
document.onkeydown = function (e)
{
e.preventDefault();
K[e.keyCode] = true;
};
document.onkeyup = function (e)
{
e.preventDefault();
K[e.keyCode] = false;
};
function VideoRoutine(dt)
{
requestAnimationFrame(VideoRoutine);
//DUMMY.rotateZ(Math.PI * 1 / 64 * (K[37] - K[39]));
//DUMMY.translateY(4 * (K[38] - K[40]));
//MAP.needsUpdate=true;
//material2.needsUpdate=true;
RENDERER.render(SCENE, CAMERA);
}
Calling the second attribute “uv1” or “uv2” doesn’t change anything.