Skip to content

Commit

Permalink
Fix transform matrix (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xintong Xia committed Jun 29, 2019
1 parent f0e1a87 commit 910db28
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 67 deletions.
29 changes: 10 additions & 19 deletions examples/3d-tiles/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {PureComponent} from 'react';
import {render} from 'react-dom';
import {StaticMap} from 'react-map-gl';
import DeckGL from '@deck.gl/react';
import {COORDINATE_SYSTEM, MapController} from '@deck.gl/core';
import {MapController} from '@deck.gl/core';
import {Vector3} from 'math.gl';
// import '@loaders.gl/polyfills';
// import '@luma.gl/debug';
Expand Down Expand Up @@ -39,8 +39,6 @@ const ADDITIONAL_EXAMPLES = {
royalExhibitionBuilding: {
tilesetUrl:
'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/3d-tiles/RoyalExhibitionBuilding/tileset.json',
coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
isWGS84: true,
depthLimit: 2, // TODO: Remove this after sse traversal is working since this is just to prevent full load of tileset
color: [115, 101, 152, 200]
}
Expand Down Expand Up @@ -249,26 +247,19 @@ export default class App extends PureComponent {
const {tilesetExampleProps} = this.state;
const {
tilesetUrl,
coordinateSystem,
coordinateOrigin,
isWGS84,
depthLimit = 5,
color = [255, 0, 0, 255]
} = tilesetExampleProps;
return (
tilesetExampleProps &&
new Tile3DLayer({
id: 'tile-3d-layer',
tilesetUrl,
coordinateSystem,
coordinateOrigin,
isWGS84,
depthLimit,
color,
onTileLoaded: this._onTileLoaded.bind(this),
onTilesetLoaded: () => this.forceUpdate()
})
);
return new Tile3DLayer({
id: 'tile-3d-layer',
tilesetUrl,
coordinateOrigin,
depthLimit,
color,
onTileLoaded: this._onTileLoaded.bind(this),
onTilesetLoaded: () => this.forceUpdate()
});
}

render() {
Expand Down
5 changes: 2 additions & 3 deletions examples/3d-tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"@loaders.gl/3d-tiles": "^1.0.3",
"@loaders.gl/core": "^1.0.3",
"@luma.gl/addons": "^7.1.0",
"@math.gl/geospatial": "^3.0.0-alpha.6",
"@math.gl/culling": "^3.0.0-alpha.6",
"@math.gl/geospatial": "^3.0.0-alpha.5",
"@probe.gl/stats-widget": "^3.0.3",
"math.gl": "^3.0.0-alpha.5",
"@loaders.gl/gltf": "^7.1.0",
"math.gl": "^3.0.0-alpha.6",
"prop-types": "^15.7.2",
"react": "^16.8.0",
"react-dom": "^16.8.0",
Expand Down
54 changes: 14 additions & 40 deletions examples/3d-tiles/tile-3d-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ import {

registerLoaders([Tile3DLoader, Tileset3DLoader, GLTFLoader]);

const DEFAULT_POINT_COLOR = [255, 0, 0, 255];
const DEFAULT_POINT_COLOR = [202, 112, 41, 255];

const defaultProps = {
// TODO - the tileset json should be an async prop.
tilesetUrl: null,
isWGS84: false,
color: DEFAULT_POINT_COLOR,
depthLimit: Number.MAX_SAFE_INTEGER,
coordinateSystem: null,
coordinateOrigin: null,
onTileLoaded: () => {},
onTilesetLoaded: () => {}
};
Expand Down Expand Up @@ -295,52 +293,28 @@ export default class Tile3DLayer extends CompositeLayer {
return {};
}

const {coordinateSystem, coordinateOrigin, isWGS84} = this.props;
const {rtcCenter} = tileHeader.content;
const {transform} = tileHeader.userData;
const {transform, positions} = tileHeader.userData;

const transformProps = {};

if (coordinateSystem) {
transformProps.coordinateSystem = coordinateSystem;
}
if (coordinateOrigin) {
transformProps.coordinateOrigin = coordinateOrigin;
}

let modelMatrix;
if (transform) {
modelMatrix = new Matrix4(transform);
}

let modelMatrix = new Matrix4(transform);
if (rtcCenter) {
modelMatrix = modelMatrix || new Matrix4();
modelMatrix.translate(rtcCenter);
transformProps.coordinateSystem =
transformProps.coordinateSystem || COORDINATE_SYSTEM.METER_OFFSETS;
}

if (isWGS84) {
transformProps.coordinateSystem = coordinateSystem || COORDINATE_SYSTEM.METER_OFFSETS;
transformProps.coordinateOrigin = coordinateOrigin;
// TODO - Heuristics to get a coordinateOrigin from the tile
// verify with spec
if (!coordinateOrigin) {
if (modelMatrix) {
const origin = new Vector3();
modelMatrix.transform(origin, origin);
transformProps.coordinateOrigin = Ellipsoid.WGS84.cartesianToCartographic(origin, origin);
modelMatrix = null;
} else {
// No model matrix, so assume bounding volume center
transformProps.coordinateOrigin = tileHeader.boundingVolume.center;
}
}
}
const firstPoint = [positions[0], positions[1], positions[2]];

if (modelMatrix) {
transformProps.modelMatrix = modelMatrix;
}
const originInCartesian = modelMatrix.transform(firstPoint, new Vector3());
const originInCarto = Ellipsoid.WGS84.cartesianToCartographic(originInCartesian, new Vector3());

const rotateMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(originInCartesian);

modelMatrix = new Matrix4(rotateMatrix.invert()).multiplyRight(modelMatrix);

transformProps.coordinateOrigin = originInCarto;
transformProps.modelMatrix = modelMatrix;
transformProps.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;

return transformProps;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gltf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@luma.gl/addons": "^7.1.0-beta.1",
"@luma.gl/constants": "^7.1.0-beta.1",
"@luma.gl/core": "^7.1.0-beta.1",
"math.gl": "^2.3.1"
"math.gl": "^3.0.0-alpha.6"
},
"devDependencies": {
"html-webpack-plugin": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/webpack.config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function addLocalDependency(config, dependency) {
return config;
}

function addLocalDevSettings(config) {
function addLocalDevSettings(config, opts) {
config = Object.assign({}, LOCAL_DEVELOPMENT_CONFIG, config);
config.resolve = config.resolve || {};
config.resolve.alias = config.resolve.alias || {};
Expand Down
6 changes: 3 additions & 3 deletions modules/3d-tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"@loaders.gl/gltf": "1.2.0-alpha.1",
"@loaders.gl/loader-utils": "1.2.0-alpha.1",
"@loaders.gl/math": "1.2.0-alpha.1",
"@math.gl/culling": "^3.0.0-alpha.5",
"@math.gl/geospatial": "^3.0.0-alpha.5",
"math.gl": "^3.0.0-alpha.5"
"@math.gl/culling": "^3.0.0-alpha.6",
"@math.gl/geospatial": "^3.0.0-alpha.6",
"math.gl": "^3.0.0-alpha.6"
}
}

0 comments on commit 910db28

Please sign in to comment.