Skip to content

Commit 5043544

Browse files
authored
Update threejs to 0.160.0 (njibhu#218)
* Update threejs to 0.160.0 * DataTexture fixes * Remove deprecated attribute * Fmt
1 parent 3dad240 commit 5043544

File tree

7 files changed

+73
-30
lines changed

7 files changed

+73
-30
lines changed

explorer/src/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AppRenderer {
1313
// Defaults
1414
this.fog = 25000;
1515
this.movementSpeed = 10000;
16-
this.lightIntensity = 0.5;
16+
this.lightIntensity = 1.25;
1717
this.loadedMapID = undefined;
1818
this.controllerType = "fly";
1919

library/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"t3d-parser": "*",
16-
"three": "0.125.0",
16+
"three": "0.160.0",
1717
"vblob": "1.0.2",
1818
"web-worker": "1.0.0"
1919
},
@@ -22,6 +22,7 @@
2222
"@rollup/plugin-json": "^6.1.0",
2323
"@rollup/plugin-node-resolve": "^15.2.3",
2424
"@rollup/plugin-typescript": "^11.1.6",
25+
"@types/three": "0.160.0",
2526
"@typescript-eslint/eslint-plugin": "8.5.0",
2627
"@typescript-eslint/parser": "8.5.0",
2728
"rollup": "4.21.3",

library/src/dataRenderer/HavokRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class HavokRenderer extends DataRenderer {
4848
renderModels(models: any, title: any, callback: Function): void {
4949
let mat;
5050
if (this.settings && this.settings.visible) {
51-
mat = new THREE.MeshNormalMaterial({ side: THREE.DoubleSide });
51+
mat = new THREE.MeshNormalMaterial({ side: THREE.DoubleSide, flatShading: true });
5252
} else if (this.settings && this.settings.export) {
5353
mat = new THREE.MeshBasicMaterial({ visible: true });
5454
} else {

library/src/dataRenderer/TerrainRenderer.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FileParser } from "t3d-parser";
77
import type LocalReader from "../LocalReader/LocalReader";
88
import type Logger from "../Logger";
99
import type { Material } from "three";
10-
import { SceneUtils } from "three/examples/jsm/utils/SceneUtils";
10+
import { createMultiMaterialObject } from "three/examples/jsm/utils/SceneUtils.js";
1111

1212
/**
1313
*
@@ -219,25 +219,22 @@ export default class TerrainRenderer extends DataRenderer {
219219
const uniforms = THREE.UniformsUtils.merge([THREE.UniformsLib["lights"]]);
220220

221221
/// TODO: READ FROM VO, don't default to hard coded scale
222-
uniforms.uvScale = { type: "v2", value: new THREE.Vector2(8.0, 8.0) };
222+
uniforms.uvScale = { value: new THREE.Vector2(8.0, 8.0) };
223223
uniforms.offset = {
224-
type: "v2",
225224
value: new THREE.Vector2(pageOffetX, pageOffetY),
226225
};
227226

228227
uniforms.texturePicker = {
229-
type: "t",
230228
value: chunkTextures[pageTexName],
231229
};
232230
uniforms.texturePicker2 = {
233-
type: "t",
234231
value: chunkTextures[pageTexName2],
235232
};
236233

237-
uniforms.texture1 = { type: "t", value: chunkTextures[fileNames[0]] };
238-
uniforms.texture2 = { type: "t", value: chunkTextures[fileNames[1]] };
239-
uniforms.texture3 = { type: "t", value: chunkTextures[fileNames[2]] };
240-
uniforms.texture4 = { type: "t", value: chunkTextures[fileNames[3]] };
234+
uniforms.texture1 = { value: chunkTextures[fileNames[0]] };
235+
uniforms.texture2 = { value: chunkTextures[fileNames[1]] };
236+
uniforms.texture3 = { value: chunkTextures[fileNames[2]] };
237+
uniforms.texture4 = { value: chunkTextures[fileNames[3]] };
241238

242239
if (self.settings && self.settings.export) {
243240
mat = new THREE.MeshBasicMaterial({ visible: true });
@@ -253,7 +250,7 @@ export default class TerrainRenderer extends DataRenderer {
253250
allMats.push(mat);
254251

255252
/// -1 for faces -> vertices , -2 for ignoring outer faces
256-
const chunkGeo = new THREE.PlaneBufferGeometry(cdx, cdy, chunkW - 3, chunkW - 3);
253+
const chunkGeo = new THREE.PlaneGeometry(cdx, cdy, chunkW - 3, chunkW - 3);
257254

258255
let cn = 0;
259256

@@ -277,16 +274,14 @@ export default class TerrainRenderer extends DataRenderer {
277274
mS.elements[5] = -1;
278275
chunkGeo.applyMatrix4(mS);
279276

280-
/// Compute face normals for lighting, not used when textured
281-
//@ts-ignore
282-
chunkGeo.computeFaceNormals();
277+
/// Compute normals for lighting
283278
chunkGeo.computeVertexNormals();
284279

285280
/// Build chunk mesh!
286281
let chunk;
287282
chunk = new THREE.Mesh(chunkGeo, customMaterial);
288283
if (Array.isArray(mat)) {
289-
chunk = SceneUtils.createMultiMaterialObject(chunkGeo as any, mat);
284+
chunk = createMultiMaterialObject(chunkGeo as any, mat);
290285
} else {
291286
chunk = new THREE.Mesh(chunkGeo, mat);
292287
}

library/src/util/MaterialUtils.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
Material,
1919
Texture,
2020
MeshPhongMaterial,
21-
MeshBasicMaterial,
21+
MeshStandardMaterial,
2222
} from "three";
2323
import type { FileParser } from "t3d-parser";
2424
import type LocalReader from "../LocalReader/LocalReader";
@@ -85,7 +85,9 @@ export function generateDataTexture(width: number, height: number, color: Color)
8585
data[stride + 3] = a;
8686
}
8787
// used the buffer to create a DataTexture
88-
return new THREE.DataTexture(data, width, height, THREE.RGBAFormat);
88+
const texture = new THREE.DataTexture(data, width, height, THREE.RGBAFormat);
89+
texture.needsUpdate = true;
90+
return texture;
8991
}
9092

9193
/**
@@ -323,7 +325,10 @@ export function getMaterial(
323325
});
324326
} /// End if material and texture
325327

326-
let finalMaterial: (MeshPhongMaterial | MeshBasicMaterial) & { textureFilename?: number; normalMap?: Texture | null };
328+
let finalMaterial: (MeshPhongMaterial | MeshStandardMaterial) & {
329+
textureFilename?: number;
330+
normalMap?: Texture | null;
331+
};
327332

328333
/// Create custom shader material if there are textures
329334
if (finalTextures) {
@@ -365,7 +370,7 @@ export function getMaterial(
365370

366371
/// Fallback material is monocolored red
367372
else {
368-
finalMaterial = new THREE.MeshBasicMaterial({
373+
finalMaterial = new THREE.MeshStandardMaterial({
369374
side: THREE.FrontSide,
370375
color: 0xff0000,
371376
flatShading: true,
@@ -453,7 +458,7 @@ export function getMaterial(
453458
if (!(grChunk.data.flags & lightMask)) {
454459
// debugger;
455460
// console.log("no light");
456-
finalMaterial = new THREE.MeshBasicMaterial({
461+
finalMaterial = new THREE.MeshStandardMaterial({
457462
side: THREE.FrontSide,
458463
map: finalMaterial.map,
459464
});
@@ -612,8 +617,8 @@ export function loadLocalTexture(
612617
/// Use RGBA for all textures for now...
613618
/// TODO: don't use alpha for some formats!
614619
texture.format =
615-
//eslint-disable-next-line no-constant-condition
616-
dxtType === 3 || dxtType === 5 || true ? THREE.RGBAFormat : THREE.RGBFormat;
620+
//dxtType === 3 || dxtType === 5 ? THREE.RGBAFormat : THREE.RGBFormat;
621+
THREE.RGBAFormat;
617622

618623
/// Update texture with the loaded image.
619624
//@ts-ignore

package-lock.json

Lines changed: 47 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"jquery": "3.5.0",
25-
"three": "0.125.0",
25+
"three": "0.160.0",
2626
"w2ui": "1.4.3"
2727
}
2828
}

0 commit comments

Comments
 (0)