Skip to content

Commit

Permalink
Merge pull request #42 from xeokit/webgl-refactorings
Browse files Browse the repository at this point in the history
More renderer functionality + demos
  • Loading branch information
xeolabs authored Jul 28, 2024
2 parents b891f1a + d674dff commit 1f8023c
Show file tree
Hide file tree
Showing 161 changed files with 17,209 additions and 987 deletions.
6 changes: 3 additions & 3 deletions packages/boundaries/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import type {FloatArrayParam, IntArrayParam, } from "@xeokit/math";
import {MAX_DOUBLE, MIN_DOUBLE, newFloatArray} from "@xeokit/math";
import {createMat4, createVec2, createVec3, lenVec3, mulMat4, subVec3} from "@xeokit/matrix";
import {decompressPoint3} from "@xeokit/compression";
import {decompressPoint3WithMat4} from "@xeokit/compression";

const tempVec3a = createVec3();
const tempVec3b = createVec3();
Expand Down Expand Up @@ -550,7 +550,7 @@ export const positions3ToAABB3 = (() => {
p[1] = positions[i + 1];
p[2] = positions[i + 2];

decompressPoint3(p, positionsDecompressMatrix, p);
decompressPoint3WithMat4(p, positionsDecompressMatrix, p);

x = p[0];
y = p[1];
Expand Down Expand Up @@ -1061,4 +1061,4 @@ export function containsAABB2Point2(aabb: FloatArrayParam, p: FloatArrayParam) {
return (
aabb[0] <= p[0] && p[0] <= aabb[3] &&
aabb[1] <= p[1] && p[1] <= aabb[4]);
}
}
102 changes: 95 additions & 7 deletions packages/compression/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export function getPositions3MinMax(array: FloatArrayParam, min?: FloatArrayPara
/**
* Creates a de-quantization matrix from a boundary.
*/
export function createPositions3DecompressMat4(aabb: FloatArrayParam, positionsDecompressMatrix: FloatArrayParam): FloatArrayParam {
export function createPositions3DecompressMat4(aabb: FloatArrayParam, positionsDecompressMatrix?: FloatArrayParam): FloatArrayParam {
positionsDecompressMatrix = positionsDecompressMatrix || createMat4();
const xmin = aabb[0];
const ymin = aabb[1];
Expand Down Expand Up @@ -284,9 +284,9 @@ export function compressPositions3(array: FloatArrayParam, min: FloatArrayParam,
* Compresses a 3D position
* @param p
* @param aabb
* @param q
* @param dest
*/
export function compressPoint3(p: FloatArrayParam, aabb: FloatArrayParam, dest: FloatArrayParam = p) {
export function compressPoint3WithAABB3(p: FloatArrayParam, aabb: FloatArrayParam, dest: FloatArrayParam = p) {
const multiplier = new Float32Array([
aabb[3] !== aabb[0] ? 65535 / (aabb[3] - aabb[0]) : 0,
aabb[4] !== aabb[1] ? 65535 / (aabb[4] - aabb[1]) : 0,
Expand All @@ -304,20 +304,40 @@ export function compressPoint3(p: FloatArrayParam, aabb: FloatArrayParam, dest:
* @param decompressMatrix
* @param dest
*/
export function decompressPoint3(position: FloatArrayParam, decompressMatrix: FloatArrayParam, dest: FloatArrayParam = position): FloatArrayParam {
export function decompressPoint3WithMat4(position: FloatArrayParam, decompressMatrix: FloatArrayParam, dest: FloatArrayParam = position): FloatArrayParam {
dest[0] = position[0] * decompressMatrix[0] + decompressMatrix[12];
dest[1] = position[1] * decompressMatrix[5] + decompressMatrix[13];
dest[2] = position[2] * decompressMatrix[10] + decompressMatrix[14];
return dest;
}

/**
* Decompresses a 3D position
* @param position
* @param aabb
* @param dest
*/
export function decompressPoint3WithAABB3(position: FloatArrayParam, aabb: FloatArrayParam, dest: FloatArrayParam = position): FloatArrayParam {
const xScale = (aabb[3] - aabb[0]) / 65535;
const xOffset = aabb[0];
const yScale = (aabb[4] - aabb[1]) / 65535;
const yOffset = aabb[1];
const zScale = (aabb[5] - aabb[2]) / 65535;
const zOffset = aabb[2];

dest[0] = position[0] * xScale + xOffset;
dest[1] = position[1] * yScale + yOffset;
dest[2] = position[2] * zScale + zOffset;
return dest;
}

/**
* Decompresses an axis-aligned 3D boundary
* @param aabb
* @param decompressMatrix
* @param dest
*/
export function decompressAABB3(aabb: FloatArrayParam, decompressMatrix: FloatArrayParam, dest: FloatArrayParam = aabb): FloatArrayParam {
export function decompressAABB3WithMat4(aabb: FloatArrayParam, decompressMatrix: FloatArrayParam, dest: FloatArrayParam = aabb): FloatArrayParam {
dest[0] = aabb[0] * decompressMatrix[0] + decompressMatrix[12];
dest[1] = aabb[1] * decompressMatrix[5] + decompressMatrix[13];
dest[2] = aabb[2] * decompressMatrix[10] + decompressMatrix[14];
Expand All @@ -327,13 +347,35 @@ export function decompressAABB3(aabb: FloatArrayParam, decompressMatrix: FloatAr
return dest;
}

/**
* Decompresses an axis-aligned 3D boundary
* @param aabb
* @param aabb2
* @param dest
*/
export function decompressAABB3WithAABB3(aabb: FloatArrayParam, aabb2: FloatArrayParam, dest: FloatArrayParam = aabb): FloatArrayParam {
const xScale = (aabb2[3] - aabb2[0]) / 65535;
const xOffset = aabb2[0];
const yScale = (aabb2[4] - aabb2[1]) / 65535;
const yOffset = aabb2[1];
const zScale = (aabb2[5] - aabb2[2]) / 65535;
const zOffset = aabb2[2];
dest[0] = aabb[0] * xScale + xOffset;
dest[1] = aabb[1] * yScale + yOffset;
dest[2] = aabb[2] * zScale + zOffset;
dest[3] = aabb[3] * xScale + xOffset;
dest[4] = aabb[4] * yScale + yOffset;
dest[5] = aabb[5] * zScale + zOffset;
return dest;
}

/**
* Decompresses a flat array of positions
* @param positions
* @param decompressMatrix
* @param dest
*/
export function decompressPositions3(positions: FloatArrayParam, decompressMatrix: FloatArrayParam, dest: Float32Array = new Float32Array(positions.length)): Float32Array {
export function decompressPositions3WithMat4(positions: FloatArrayParam, decompressMatrix: FloatArrayParam, dest: Float32Array = new Float32Array(positions.length)): Float32Array {
for (let i = 0, len = positions.length; i < len; i += 3) {
dest[i + 0] = positions[i + 0] * decompressMatrix[0] + decompressMatrix[12];
dest[i + 1] = positions[i + 1] * decompressMatrix[5] + decompressMatrix[13];
Expand All @@ -342,6 +384,27 @@ export function decompressPositions3(positions: FloatArrayParam, decompressMatri
return dest;
}

/**
* Decompresses a flat array of positions
* @param positions
* @param decompressMatrix
* @param dest
*/
export function decompressPositions3WithAABB3(positions: FloatArrayParam, aabb: FloatArrayParam, dest: Float32Array = new Float32Array(positions.length)): Float32Array {
const xScale = (aabb[3] - aabb[0]);
const xOffset = aabb[0];
const yScale = (aabb[4] - aabb[1]);
const yOffset = aabb[1];
const zScale = (aabb[5] - aabb[2]);
const zOffset = aabb[2];
for (let i = 0, len = positions.length; i < len; i += 3) {
dest[i + 0] = positions[i + 0] * xScale + xOffset;
dest[i + 1] = positions[i + 1] * yScale + yOffset;
dest[i + 2] = positions[i + 2] * zScale + zOffset;
}
return dest;
}

/**
* Gets the 2D min/max boundary of a flat array of UV coordinate
* @param array
Expand Down Expand Up @@ -577,7 +640,7 @@ function octDecodeVec2s(octs: Int8Array, result: FloatArrayParam): FloatArrayPar
/**
* @private
*/
export function quantizePositions3(positions: FloatArrayParam, aabb: FloatArrayParam, positionsDecompressMatrix: FloatArrayParam) { // http://cg.postech.ac.kr/research/mesh_comp_mobile/mesh_comp_mobile_conference.pdf
export function quantizePositions3AndCreateMat4(positions: FloatArrayParam, aabb: FloatArrayParam, positionsDecompressMatrix: FloatArrayParam) { // http://cg.postech.ac.kr/research/mesh_comp_mobile/mesh_comp_mobile_conference.pdf
const lenPositions = positions.length;
const positionsCompressed = new Uint16Array(lenPositions);
const xmin = aabb[0];
Expand All @@ -604,6 +667,31 @@ export function quantizePositions3(positions: FloatArrayParam, aabb: FloatArrayP
return positionsCompressed;
}

/**
* @private
*/
export function quantizePositions3(positions: FloatArrayParam, aabb: FloatArrayParam) { // http://cg.postech.ac.kr/research/mesh_comp_mobile/mesh_comp_mobile_conference.pdf
const lenPositions = positions.length;
const positionsCompressed = new Uint16Array(lenPositions);
const xmin = aabb[0];
const ymin = aabb[1];
const zmin = aabb[2];
const xwid = aabb[3] - xmin;
const ywid = aabb[4] - ymin;
const zwid = aabb[5] - zmin;
const maxInt = 65525;
const xMultiplier = maxInt / xwid;
const yMultiplier = maxInt / ywid;
const zMultiplier = maxInt / zwid;
const verify = (num: number) => num >= 0 ? num : 0;
for (let i = 0; i < lenPositions; i += 3) {
positionsCompressed[i + 0] = Math.floor(verify(positions[i + 0] - xmin) * xMultiplier);
positionsCompressed[i + 1] = Math.floor(verify(positions[i + 1] - ymin) * yMultiplier);
positionsCompressed[i + 2] = Math.floor(verify(positions[i + 2] - zmin) * zMultiplier);
}
return positionsCompressed;
}

/**
* @private
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/config/tsconfig.typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"path": "packages/utils"
},
{
"path": "packages/cameraControl"
"path": "packages/cameracontrol"
},
{
"path": "packages/cityjson"
Expand Down Expand Up @@ -111,6 +111,12 @@
},
{
"path": "packages/testutils"
},
{
"path": "packages/metamodel"
},
{
"path": "packages/xkt"
}
]
}
}
40 changes: 22 additions & 18 deletions packages/data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"extends": "@xeokit/config/tsconfig.package.json",
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
},
"references": [
{
"path": "../core"
}
]
}
"extends": "@xeokit/config/tsconfig.package.json",
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
},
"references": [

{
"path": "../core"
},
{
"path": "../basictypes"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h3>Major components used</h3>

import {log} from "../../js/logger.js";

//-----------------------------------------------------------------------------------------
// Import xeokit SDK from the JavaScript bundle that we've built for these examples
//-----------------------------------------------------------------------------------------

import * as xeokit from "./../../js/xeokit-demo-bundle.js";

const scene = new xeokit.scene.Scene();
Expand Down
Loading

0 comments on commit 1f8023c

Please sign in to comment.