Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mg/points with meshes #43

Merged
merged 2 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pybabylonjs/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
48 changes: 30 additions & 18 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand All @@ -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){
Expand All @@ -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) {
Expand All @@ -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}) {
Expand Down
62 changes: 53 additions & 9 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -225,11 +227,55 @@ export class BabylonPointCloudView extends BabylonBaseView {

const tasks:Promise<any>[] = [];


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<gltfData.length; i++){
var blob = new Blob([gltfData[i]]);
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];
}
));
}
}

}

// needed to force then synchronous
// because we needed the model loaded
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down