diff --git a/pybabylonjs/args.py b/pybabylonjs/args.py index a00f11c..77ef5a2 100644 --- a/pybabylonjs/args.py +++ b/pybabylonjs/args.py @@ -25,14 +25,16 @@ "crs": "EPSG:2994", "topo_offset": 0, "gltf_data": None, + "gltf_multi": False, "name_space": None, "array_name": None, "token": None, "tiledb_env": None, "show_fraction": None, - "origin_shift_x": None, - "origin_shift_y": None, - "origin_shift_z": None, + "point_shift": [None, None, None], + "mesh_shift": [0, 0, 0], + "mesh_rotation": [0, 0, 0], + "mesh_scale": [1, 1, 1], "distance_colors": False, } diff --git a/src/data.ts b/src/data.ts index 166ee4e..290b5fb 100644 --- a/src/data.ts +++ b/src/data.ts @@ -18,8 +18,6 @@ export function setPointCloudSwitches(mode: string){ isTopo = true; }else if(mode == "gltf"){ isGltf = true; - //}else if(mode == "pcl"){ - // isPCL = true; } return {isTime, isClass, isTopo, isGltf} } @@ -46,19 +44,15 @@ export async function getPointCloud(values: any){ data = dataIn; } - if (values.origin_shift_x){ - data.X = data.X.map((n: any) => n + values.origin_shift_x); + if (values.point_shift[0]){ + data.X = data.X.map((n: any) => n + values.point_shift[0]); + data.Y = data.Y.map((n: any) => n + values.point_shift[1]); + data.Z = data.Z.map((n: any) => n + values.point_shift[2]); } - if (values.origin_shift_y){ - data.Y = data.Y.map((n: any) => n + values.origin_shift_y); - } - if (values.origin_shift_z){ - data.Z = data.Z.map((n: any) => n + values.origin_shift_z); - } - - const {xmin, xmax, ymin, ymax, rgbMax} = getPointCloudLimits(values, data); - return {data, xmin, xmax, ymin, ymax, rgbMax}; + const {xmin, xmax, ymin, ymax, zmin, zmax, rgbMax} = getPointCloudLimits(values, data); + + return {data, xmin, xmax, ymin, ymax, zmin, zmax, rgbMax}; } function getPointCloudLimits(values: any, data: any){ @@ -67,19 +61,37 @@ function getPointCloudLimits(values: any, data: any){ var xmax: number; var ymin: number; var ymax: number; + var zmin: number; + var zmax: number; var rgbMax: number; if (values.bbox) { - xmin = values.bbox.X[0]; - xmax = values.bbox.X[1]; - ymin = values.bbox.Y[0]; - ymax = values.bbox.Y[1]; + if (values.point_shift[0]) + { + xmin = values.bbox.X[0] + values.point_shift[0]; + xmax = values.bbox.X[1] + values.point_shift[0]; + ymin = values.bbox.Y[0] + values.point_shift[1]; + ymax = values.bbox.Y[1] + values.point_shift[1]; + zmin = values.bbox.Z[0] + values.point_shift[2]; + zmax = values.bbox.Z[1] + values.point_shift[2]; + } + else + { + xmin = values.bbox.X[0]; + xmax = values.bbox.X[1]; + ymin = values.bbox.Y[0]; + ymax = values.bbox.Y[1]; + zmin = values.bbox.Z[0]; + zmax = values.bbox.Z[1]; + } } else { xmin = data.X.reduce((accum: number, currentNumber: number) => Math.min(accum, currentNumber)); xmax = data.X.reduce((accum: number, currentNumber: number) => Math.max(accum, currentNumber)); ymin = data.Y.reduce((accum: number, currentNumber: number) => Math.min(accum, currentNumber)); ymax = data.Y.reduce((accum: number, currentNumber: number) => Math.max(accum, currentNumber)); + zmin = data.Z.reduce((accum: number, currentNumber: number) => Math.min(accum, currentNumber)); + zmax = data.Z.reduce((accum: number, currentNumber: number) => Math.max(accum, currentNumber)); } if (values.rgb_max) { @@ -91,7 +103,7 @@ function getPointCloudLimits(values: any, data: any){ const bluemax = data.Blue.reduce((accum: number, currentNumber: number) => Math.max(accum, currentNumber)); rgbMax = Math.max(redmax, greenmax, bluemax); } - return {xmin, xmax, ymin, ymax, rgbMax}; + return {xmin, xmax, ymin, ymax, zmin, zmax, rgbMax}; } async function loadPointCloud(values: {name_space: string, array_name: string, bbox: { X: number[], Y: number[], Z: number[]}, token: string, tiledb_env: string}) { diff --git a/src/widget.ts b/src/widget.ts index 05844a3..d845b39 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -142,12 +142,14 @@ export class BabylonPointCloudView extends BabylonBaseView { const {isTime, isClass, isTopo, isGltf} = setPointCloudSwitches(this.values.mode); - var {data, xmin, xmax, ymin, ymax, rgbMax} = await getPointCloud(this.values).then((results) => {return results}); + var {data, xmin, xmax, ymin, ymax, zmin, zmax, rgbMax} = await getPointCloud(this.values).then((results) => {return results}); const size_x = xmax - xmin; const size_y = ymax - ymin; + const size_z = zmax - zmin; const center_x = xmin + size_x / 2; const center_y = ymin + size_y / 2; + const center_z = zmin + size_z / 2; const numCoords = data.X.length; const times = data.GpsTime; @@ -225,11 +227,55 @@ export class BabylonPointCloudView extends BabylonBaseView { const tasks:Promise[] = []; + if (isGltf) { - var blob = new Blob([gltfData]); - var url = URL.createObjectURL(blob); - tasks.push(SceneLoader.AppendAsync(url, "", scene, null, ".gltf")); - }; + + if (this.values.gltf_multi===false){ + var blob = new Blob([gltfData]); + var url = URL.createObjectURL(blob); + + tasks.push(SceneLoader.ImportMeshAsync('', url, '', scene, null, '.gltf').then( + container => { + + container.meshes[0].rotation = new Vector3( + this.values.mesh_rotation[0], + this.values.mesh_rotation[1], + this.values.mesh_rotation[2]); + container.meshes[0].scaling = new Vector3( + this.values.mesh_scale[0], + this.values.mesh_scale[1], + this.values.mesh_scale[2]); + container.meshes[0].position.x = container.meshes[0].position.x + this.values.mesh_shift[0]; + container.meshes[0].position.y = container.meshes[0].position.y + this.values.mesh_shift[1]; + container.meshes[0].position.z = container.meshes[0].position.z + this.values.mesh_shift[2]; + } + )); + } + else if (this.values.gltf_multi===true) { + for (let i=0; i { + + container.meshes[0].rotation = new Vector3( + this.values.mesh_rotation[0], + this.values.mesh_rotation[1], + this.values.mesh_rotation[2]); + container.meshes[0].scaling = new Vector3( + this.values.mesh_scale[0], + this.values.mesh_scale[1], + this.values.mesh_scale[2]); + container.meshes[0].position.x = container.meshes[0].position.x + this.values.mesh_shift[0]; + container.meshes[0].position.y = container.meshes[0].position.y + this.values.mesh_shift[1]; + container.meshes[0].position.z = container.meshes[0].position.z + this.values.mesh_shift[2]; + } + )); + } + } + + } // needed to force then synchronous // because we needed the model loaded @@ -239,8 +285,6 @@ export class BabylonPointCloudView extends BabylonBaseView { tasks.push(pcs.buildMeshAsync()); await Promise.all(tasks); - scene.createDefaultCameraOrLight(true, true, false); - if (isTime || isClass) { var advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI( @@ -450,10 +494,10 @@ export class BabylonPointCloudView extends BabylonBaseView { if (this.wheelPrecision > 0) camera.wheelPrecision = this.wheelPrecision; - camera.setTarget(new Vector3((xmin + xmax) / 2, 0, (ymin + ymax) / 2)); + camera.setTarget(new Vector3(center_x, center_z, center_y)); this._cameras.push(camera); - const camera2 = new FreeCamera('free', new Vector3(center_x, 0, center_y), scene); + const camera2 = new FreeCamera('free', new Vector3(center_x, center_z, center_y), scene); camera2.minZ = camera.minZ; camera2.maxZ = camera.maxZ; if (this.moveSpeed > 0) {