-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dito.ts for bounding volume computations
- Loading branch information
Showing
8 changed files
with
1,027 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"name": "dito.ts", | ||
"license": ["BSD-2-Clause"], | ||
"url": "https://github.com/Esri/dito.ts", | ||
"notes": "Commit a7cfa662d1a6d6f0f387deaa1fb9d8edb6f298bc" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Quaternion } from "cesium"; | ||
import { Matrix4 } from "cesium"; | ||
import { Cartesian3 } from "cesium"; | ||
import { OrientedBoundingBox } from "cesium"; | ||
|
||
import { computeOBB } from "./external/dito"; | ||
import { Obb } from "./external/dito"; | ||
|
||
/** | ||
* Methods for computing oriented bounding boxes. | ||
* | ||
* @internal | ||
*/ | ||
export class OrientedBoundingBoxes { | ||
/** | ||
* Compute a bounding volume box for the given points. | ||
* | ||
* This will return the 12-element array that can be used | ||
* as the `boundingVolume.box` in a tileset JSON. | ||
* | ||
* @param points - The points, as 3-element arrays | ||
* @returns The bounding volume box | ||
*/ | ||
static fromPoints(points: number[][]): number[] { | ||
//return OrientedBoundingBoxes.fromPointsCesium(points); | ||
return OrientedBoundingBoxes.fromPointsDitoTs(points); | ||
} | ||
|
||
/** | ||
* Implementation of 'fromPoints' based on CesiumJS | ||
* | ||
* @param points - The points, as 3-element arrays | ||
* @returns The bounding volume box | ||
*/ | ||
static fromPointsCesium(points: number[][]): number[] { | ||
const positions = points.map( | ||
(p: number[]) => new Cartesian3(p[0], p[1], p[2]) | ||
); | ||
const obb = OrientedBoundingBox.fromPoints(positions, undefined); | ||
const result = Array<number>(12); | ||
OrientedBoundingBox.pack(obb, result, 0); | ||
return result; | ||
} | ||
|
||
/** | ||
* Implementation of 'fromPoints' based on dito.ts | ||
* | ||
* @param points - The points, as 3-element arrays | ||
* @returns The bounding volume box | ||
*/ | ||
static fromPointsDitoTs(points: number[][]): number[] { | ||
const attribute = { | ||
data: points.flat(), | ||
size: 3, | ||
offsetIdx: 0, | ||
strideIdx: 3, | ||
}; | ||
const obb: Obb = { | ||
center: new Float64Array(3), | ||
halfSize: new Float32Array(3), | ||
quaternion: new Float32Array(4), | ||
}; | ||
computeOBB(attribute, obb); | ||
|
||
const translation = Cartesian3.unpack([...obb.center]); | ||
const rotation = Quaternion.unpack([...obb.quaternion]); | ||
const scale = Cartesian3.unpack( | ||
[...obb.halfSize].map((v: number) => v * 2) | ||
); | ||
const matrix = Matrix4.fromTranslationQuaternionRotationScale( | ||
translation, | ||
rotation, | ||
scale, | ||
new Matrix4() | ||
); | ||
const cesiumObb = OrientedBoundingBox.fromTransformation(matrix, undefined); | ||
const result = Array<number>(12); | ||
OrientedBoundingBox.pack(cesiumObb, result, 0); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
The file 'dito.ts' is taken from https://github.com/Esri/dito.ts | ||
|
||
Commit a7cfa662d1a6d6f0f387deaa1fb9d8edb6f298bc (with minor changes to prevent type errors) | ||
|
||
Original license statement: | ||
|
||
--- | ||
|
||
This project is distributed under the following BSD license: | ||
|
||
Copyright 2018 Stefan Eilemann. | ||
Copyright 2011 Thomas Larsson and Linus Kallberg (C++ implementation). | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are | ||
permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of | ||
conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
of conditions and the following disclaimer in the documentation and/or other materials | ||
provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THOMAS LARSSON AND LINUS KALLBERG ``AS IS'' AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THOMAS LARSSON, LINUS | ||
KALLBERG, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
--- | ||
|
Oops, something went wrong.