@cognite/3d-viewer
Advanced tools
Comparing version 3.7.1 to 3.7.2
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
## [3.7.2] - 2018-11-14 | ||
### Fixed | ||
- Fixed issue where `noBackground` to `Cognite3DViewer.constructor` was ignored. | ||
- Corrected validation to check if `Cognite3DViewer.canvas` is visible in DOM (avoid WebGL warnings). | ||
### Added | ||
- Added test to verify correct timestamps on build files. | ||
- Improved documentation in `README.md`: | ||
- Added code snippet for using saved camera position from the REST API. | ||
- Updated docs for `Cognite3DModel.getBoundingBox` to reflect that resulting bounding box is in model space by default. | ||
- Improved test to catch the fixes that was solved. | ||
## [3.7.1] - 2018-11-13 | ||
@@ -5,0 +17,0 @@ ### Fixed |
{ | ||
"name": "@cognite/3d-viewer", | ||
"version": "3.7.1", | ||
"version": "3.7.2", | ||
"description": "JavaScript viewer to visualize 3D models on Cognite's Data Platform", | ||
@@ -27,10 +27,10 @@ "contributors": [ | ||
"clean": "[ ! -d dist ] || rm -r dist", | ||
"build": "NODE_ENV=production node build/build.js && yarn run esCheck && yarn run moveTypes && yarn run moveChangelog", | ||
"build": "NODE_ENV=production node build/build.js && yarn run esCheck && yarn run moveTypes && yarn run validateTimestamps", | ||
"build:dev": "NODE_ENV=development node build/build.js", | ||
"buildDocs": "yarn run documentation readme 'src/**' --section='API Reference' --format=md --access='public' && yarn run validateDocLinks", | ||
"validateDocLinks": "yarn markdown-link-check README.md && yarn markdown-link-check README-dev.md ", | ||
"validateTimestamps": "node ./scripts/validateTimestamps.js", | ||
"prepublishOnly": "rm -rf dist/ && npm run build", | ||
"esCheck": "yarn run es-check es5 './dist/**/*.js'", | ||
"moveTypes": "cp ./src/index.d.ts ./dist/", | ||
"moveChangelog": "cp ./CHANGELOG.md ./dist/", | ||
"lint": "eslint src test", | ||
@@ -37,0 +37,0 @@ "test": "true", |
@@ -107,3 +107,3 @@ # Cognite 3D Web Viewer | ||
// make the camera zoom to the object | ||
const boundingBox = model.getBoundingBox(nodeId); | ||
const boundingBox = model.getBoundingBox(nodeId, null, model.matrix); | ||
viewer.fitCameraToBoundingBox(boundingBox, 2000); // 2 sec | ||
@@ -116,2 +116,25 @@ } else { | ||
#### Load saved camera position from the API | ||
Assume you have the revision object from Cognite's Data Platform which you can get from this [endpoint](https://doc.cognitedata.com/api/0.6/#operation/getRevision). | ||
Here is a code snippet to use the saved camera position: | ||
```js | ||
const { target, position } = revision.camera; | ||
if (Array.isArray(target) && Array.isArray(position)) { | ||
// Create three.js objects | ||
const positionVector = new THREE.Vector3(...position); | ||
const targetVector = new THREE.Vector3(...target); | ||
// Apply transformation matrix | ||
positionVector.applyMatrix4(model.matrix); | ||
targetVector.applyMatrix4(model.matrix); | ||
// Set on viewer | ||
viewer.setCameraPosition(positionVector); | ||
viewer.setCameraTarget(targetVector); | ||
} else { | ||
viewer.fitCameraToModel(model, 0); | ||
} | ||
``` | ||
## API Reference | ||
@@ -419,3 +442,3 @@ | ||
Returns **THREE.Vector3** Position in global space | ||
Returns **THREE.Vector3** Position in world space | ||
@@ -432,3 +455,3 @@ #### getCameraTarget | ||
Returns **THREE.Vector3** Target in global space | ||
Returns **THREE.Vector3** Target in world space | ||
@@ -441,3 +464,3 @@ #### setCameraPosition | ||
- `position` **THREE.Vector3** \-- Position in global space | ||
- `position` **THREE.Vector3** \-- Position in world space | ||
@@ -461,3 +484,3 @@ ##### Examples | ||
- `target` **THREE.Vector3** \-- Target in global space | ||
- `target` **THREE.Vector3** \-- Target in world space | ||
@@ -477,7 +500,7 @@ ##### Examples | ||
Move camera to a place where the content of a bounding box is visible to the camera | ||
Move camera to a place where the content of a bounding box is visible to the camera. | ||
##### Parameters | ||
- `box` **THREE.Box3** \-- The bounding box | ||
- `box` **THREE.Box3** \-- The bounding box in world space | ||
- `duration` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- The duration of the animation moving the camera. Set this to 0 (zero) to disable animation. | ||
@@ -627,3 +650,3 @@ - `radiusFactor` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- The the ratio of the distance from camera to center of box and radius of the box (optional, default `4`) | ||
const reusableBox = new THREE.Box3(); | ||
const box = model.getBoundingBox(nodeId, reusableBox, model.matrix); | ||
const box = model.getBoundingBox(nodeId, reusableBox, model.matrix); // world space | ||
// box === reusableBox | ||
@@ -630,0 +653,0 @@ ``` |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
869
938330
5