Skip to content
42 changes: 27 additions & 15 deletions frontend/javascripts/libs/UpdatableTexture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import * as THREE from "three";
import {
LinearFilter,
LinearMipMapLinearFilter,
type MagnificationTextureFilter,
type Mapping,
type MinificationTextureFilter,
type PixelFormat,
Texture,
type TextureDataType,
type WebGLRenderer,
WebGLUtils,
type Wrapping,
} from "three";
import type { TypedArray } from "viewer/constants";

/* The UpdatableTexture class exposes a way to partially update a texture.
Expand All @@ -17,24 +29,24 @@ import type { TypedArray } from "viewer/constants";
*/
let originalTexSubImage2D: WebGL2RenderingContext["texSubImage2D"] | null = null;

class UpdatableTexture extends THREE.Texture {
class UpdatableTexture extends Texture {
isUpdatableTexture: boolean = true;
renderer!: THREE.WebGLRenderer;
renderer!: WebGLRenderer;
gl!: WebGL2RenderingContext;
utils!: THREE.WebGLUtils;
utils!: WebGLUtils;
width: number | undefined;
height: number | undefined;

constructor(
width: number,
height: number,
format?: THREE.PixelFormat,
type?: THREE.TextureDataType,
mapping?: THREE.Mapping,
wrapS?: THREE.Wrapping,
wrapT?: THREE.Wrapping,
magFilter?: THREE.MagnificationTextureFilter,
minFilter?: THREE.MinificationTextureFilter,
format?: PixelFormat,
type?: TextureDataType,
mapping?: Mapping,
wrapS?: Wrapping,
wrapT?: Wrapping,
magFilter?: MagnificationTextureFilter,
minFilter?: MinificationTextureFilter,
anisotropy?: number,
) {
const imageData = { width, height, data: new Uint32Array(0) };
Expand All @@ -52,18 +64,18 @@ class UpdatableTexture extends THREE.Texture {
anisotropy,
);

this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
this.generateMipmaps = false;
this.flipY = false;
this.unpackAlignment = 1;
this.needsUpdate = true;
}

setRenderer(renderer: THREE.WebGLRenderer) {
setRenderer(renderer: WebGLRenderer) {
this.renderer = renderer;
this.gl = this.renderer.getContext() as WebGL2RenderingContext;
this.utils = new THREE.WebGLUtils(this.gl, this.renderer.extensions);
this.utils = new WebGLUtils(this.gl, this.renderer.extensions);
}

isInitialized() {
Expand Down
6 changes: 3 additions & 3 deletions frontend/javascripts/libs/compute_bvh_async.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type * as THREE from "three";
import type { BufferGeometry } from "three";
import type { MeshBVH } from "three-mesh-bvh";
// @ts-ignore
import { GenerateMeshBVHWorker } from "three-mesh-bvh/src/workers/GenerateMeshBVHWorker";

const bvhWorker = new GenerateMeshBVHWorker();
const bvhQueue: Array<{
geometry: THREE.BufferGeometry;
geometry: BufferGeometry;
resolve: (bvh: MeshBVH) => void;
reject: (error: unknown) => void;
}> = [];
Expand All @@ -32,7 +32,7 @@ async function processBvhQueue() {
}
}

export async function computeBvhAsync(geometry: THREE.BufferGeometry): Promise<MeshBVH> {
export async function computeBvhAsync(geometry: BufferGeometry): Promise<MeshBVH> {
return new Promise((resolve, reject) => {
bvhQueue.push({ geometry, resolve, reject });
processBvhQueue();
Expand Down
10 changes: 5 additions & 5 deletions frontend/javascripts/libs/cuckoo/abstract_cuckoo_table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type UpdatableTexture from "libs/UpdatableTexture";
import * as THREE from "three";
import { type PixelFormat, type PixelFormatGPU, RGBAIntegerFormat, UnsignedIntType } from "three";
import { getRenderer } from "viewer/controller/renderer";
import { createUpdatableTexture } from "viewer/geometries/materials/plane_material_factory_helpers";

Expand Down Expand Up @@ -30,14 +30,14 @@ export abstract class AbstractCuckooTable<K, V, Entry extends [K, V]> {
}

static getTextureType() {
return THREE.UnsignedIntType;
return UnsignedIntType;
}

static getTextureFormat(): THREE.PixelFormat {
return THREE.RGBAIntegerFormat;
static getTextureFormat(): PixelFormat {
return RGBAIntegerFormat;
}

static getInternalFormat(): THREE.PixelFormatGPU {
static getInternalFormat(): PixelFormatGPU {
return "RGBA32UI";
}

Expand Down
6 changes: 3 additions & 3 deletions frontend/javascripts/libs/cuckoo/cuckoo_table_uint32.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as THREE from "three";
import { type PixelFormatGPU, RGIntegerFormat } from "three";
import type { NumberLike } from "viewer/store";
import { AbstractCuckooTable, EMPTY_KEY_VALUE } from "./abstract_cuckoo_table";

Expand All @@ -18,9 +18,9 @@ export class CuckooTableUint32 extends AbstractCuckooTable<Key, Value, Entry> {
return 2;
}
static getTextureFormat() {
return THREE.RGIntegerFormat;
return RGIntegerFormat;
}
static getInternalFormat(): THREE.PixelFormatGPU {
static getInternalFormat(): PixelFormatGPU {
return "RG32UI";
}
static fromCapacity(requestedCapacity: number): CuckooTableUint32 {
Expand Down
2 changes: 2 additions & 0 deletions frontend/javascripts/libs/mjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// https://github.com/imbcmdth/mjs/blob/master/index.js
// for all functions in M4x4, V2 and V3.
import _ from "lodash";
import type { Vector3 as ThreeVector3 } from "three";
import type { Vector2, Vector3, Vector4 } from "viewer/constants";
import { chunk3 } from "viewer/model/helpers/chunk";

Expand Down Expand Up @@ -274,6 +275,7 @@ function round(v: Vector3Like, r?: Float32Array | null | undefined) {
}

// @ts-ignore TS claims that the implementation doesn't match the overloading
function divide3(a: ThreeVector3, k: ThreeVector3, r?: ThreeVector3): Vector3;
function divide3(a: Vector3, k: Vector3, r?: Vector3): Vector3;
function divide3(a: Float32Array, k: Float32Array, r?: Float32Array) {
if (r == null) r = new Float32Array(3);
Expand Down
8 changes: 4 additions & 4 deletions frontend/javascripts/libs/order_points_with_mst.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as THREE from "three";
import type { Vector3 } from "three";

export function orderPointsWithMST(points: THREE.Vector3[]): THREE.Vector3[] {
export function orderPointsWithMST(points: Vector3[]): Vector3[] {
/*
* Find the order of points with the shortest distance heuristically.
* This is done by computing the MST of the points and then traversing
Expand Down Expand Up @@ -63,7 +63,7 @@ interface Edge {
dist: number;
}

function computeMST(points: THREE.Vector3[]): number[][] {
function computeMST(points: Vector3[]): number[][] {
const edges: Edge[] = [];
const numPoints = points.length;

Expand Down Expand Up @@ -110,7 +110,7 @@ function traverseMstDfs(mst: number[][], startIdx = 0): number[] {
return orderedPoints;
}

function computePathLength(points: THREE.Vector3[], order: number[]): number {
function computePathLength(points: Vector3[], order: number[]): number {
let length = 0;
for (let i = 0; i < order.length - 1; i++) {
length += points[order[i]].distanceTo(points[order[i + 1]]);
Expand Down
20 changes: 10 additions & 10 deletions frontend/javascripts/libs/parse_stl_buffer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck

/* eslint-disable */
import * as THREE from "three";
import { BufferAttribute, BufferGeometry, Float32BufferAttribute, LoaderUtils, Vector3 } from "three";
/**
* @author aleeper / http://adamleeper.com/
* @author mrdoob / http://mrdoob.com/
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function parse(data) {

var dataOffset = 84;
var faceLength = 12 * 4 + 2;
var geometry = new THREE.BufferGeometry();
var geometry = new BufferGeometry();
var vertices = [];
var normals = [];

Expand Down Expand Up @@ -141,11 +141,11 @@ export default function parse(data) {
}
}

geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array(vertices), 3));
geometry.setAttribute("normal", new THREE.BufferAttribute(new Float32Array(normals), 3));
geometry.setAttribute("position", new BufferAttribute(new Float32Array(vertices), 3));
geometry.setAttribute("normal", new BufferAttribute(new Float32Array(normals), 3));

if (hasColors) {
geometry.setAttribute("color", new THREE.BufferAttribute(new Float32Array(colors), 3));
geometry.setAttribute("color", new BufferAttribute(new Float32Array(colors), 3));
geometry.hasColors = true;
geometry.alpha = alpha;
}
Expand All @@ -154,15 +154,15 @@ export default function parse(data) {
}

function parseASCII(data) {
var geometry = new THREE.BufferGeometry();
var geometry = new BufferGeometry();
var patternFace = /facet([\s\S]*?)endfacet/g;
var faceCounter = 0;
var patternFloat = /[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source;
var patternVertex = new RegExp("vertex" + patternFloat + patternFloat + patternFloat, "g");
var patternNormal = new RegExp("normal" + patternFloat + patternFloat + patternFloat, "g");
var vertices = [];
var normals = [];
var normal = new THREE.Vector3();
var normal = new Vector3();
var result;

while ((result = patternFace.exec(data)) !== null) {
Expand Down Expand Up @@ -200,14 +200,14 @@ export default function parse(data) {
faceCounter++;
}

geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
return geometry;
}

function ensureString(buffer) {
if (typeof buffer !== "string") {
return THREE.LoaderUtils.decodeText(new Uint8Array(buffer));
return LoaderUtils.decodeText(new Uint8Array(buffer));
}

return buffer;
Expand Down
18 changes: 9 additions & 9 deletions frontend/javascripts/libs/stl_exporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import * as THREE from "three";
import { Scene, Vector3 } from "three";

// Original Source: https://github.com/mrdoob/three.js/blob/master/examples/js/exporters/STLExporter.js
// Manual changes:
Expand Down Expand Up @@ -34,7 +34,7 @@ class ChunkedDataView {
}

class STLExporter {
parse(scene: THREE.Scene, options: any = {}) {
parse(scene: Scene, options: any = {}) {
const binary = options.binary !== undefined ? options.binary : false; //

const objects: any[] = [];
Expand All @@ -44,7 +44,7 @@ class STLExporter {
const geometry = object.geometry;

if (geometry.isBufferGeometry !== true) {
throw new Error("STLExporter: Geometry is not of type THREE.BufferGeometry.");
throw new Error("STLExporter: Geometry is not of type BufferGeometry.");
}

const index = geometry.index;
Expand Down Expand Up @@ -82,12 +82,12 @@ class STLExporter {
outputString += "solid exported\n";
}

const vA = new THREE.Vector3();
const vB = new THREE.Vector3();
const vC = new THREE.Vector3();
const cb = new THREE.Vector3();
const ab = new THREE.Vector3();
const normal = new THREE.Vector3();
const vA = new Vector3();
const vB = new Vector3();
const vC = new Vector3();
const cb = new Vector3();
const ab = new Vector3();
const normal = new Vector3();

for (let i = 0, il = objects.length; i < il; i++) {
const object = objects[i].object3d;
Expand Down
Loading