Skip to content

Commit

Permalink
Merge pull request #337 from Smithsonian/rc-47
Browse files Browse the repository at this point in the history
Rc 47
  • Loading branch information
gjcope authored Dec 20, 2024
2 parents 5728312 + d8d3f05 commit 894eadc
Show file tree
Hide file tree
Showing 21 changed files with 361 additions and 256 deletions.
2 changes: 1 addition & 1 deletion libs/ff-ui/source/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class Popup extends CustomElement
super.firstConnected();

this.setStyle({
position: "fixed",
position: "absolute",
zIndex: "1000"
});

Expand Down
314 changes: 144 additions & 170 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voyager",
"version": "0.46.1",
"version": "0.47.0",
"description": "Smithsonian DPO Voyager - 3D Explorer and Tool Suite",
"scripts": {
"start": "npm run server",
Expand Down Expand Up @@ -28,13 +28,13 @@
"node_modules/@ff/core",
"node_modules/@ff/server"
],
"ignore": [
"**/files/**",
"**/.git/**"
]
"ignore": [
"**/files/**",
"**/.git/**"
]
},
"engines": {
"node": ">=14.15.0"
"node": ">=16.20.2"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -86,7 +86,7 @@
"devDependencies": {
"@types/chai": "^4.2.21",
"@types/mocha": "^9.0.0",
"@types/node": "^14.0.26",
"@types/node": "^16.18.108",
"@types/three": "^0.168.0",
"chai": "^4.3.8",
"concurrently": "^6.2.1",
Expand All @@ -98,7 +98,7 @@
"html-webpack-plugin": "^5.3.2",
"license-checker": "^25.0.1",
"mini-css-extract-plugin": "^2.2.0",
"mocha": "^10.2.0",
"mocha": "^10.8.2",
"raw-loader": "^4.0.2",
"sass": "^1.77.5",
"sass-loader": "^13.3.3",
Expand Down
5 changes: 3 additions & 2 deletions source/client/components/CVARManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,12 @@ export default class CVARManager extends Component

protected placeModel( hit: Vector3 ) {
const scene = this.vScene.scene!;
const sizeLimit = 0.15/this.ins.arScale.value;
const isWall = this.ins.wallMount.value === true;
const {min, max} = _boundingBox;
const boundingRadius = this.sceneNode.outs.boundingRadius.value;
const width = Math.max((max.x-min.x)*1.25, 0.15);
const height = isWall ? Math.max((max.y-min.y)*1.25, 0.15) : Math.max((max.z-min.z)*1.25, 0.15);
const width = Math.max((max.x-min.x)*1.25, sizeLimit);
const height = isWall ? Math.max((max.y-min.y)*1.25, sizeLimit) : Math.max((max.z-min.z)*1.25, sizeLimit);
const centerOffsetX = (min.x+max.x)/2.0;
const centerOffsetZ = (min.z+max.z)/2.0;
const centerOffsetY = (min.y+max.y)/2.0;
Expand Down
11 changes: 7 additions & 4 deletions source/client/components/CVAnnotationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import CVAudioManager from "./CVAudioManager";
import CVAssetManager from "./CVAssetManager";
import CVSnapshots from "./CVSnapshots";
import CPulse from "client/../../libs/ff-graph/source/components/CPulse";
import CVScene from "./CVScene";

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -631,12 +632,14 @@ export default class CVAnnotationView extends CObject3D
angleOffset += Math.abs(n-viewState.values[orbitIdx][i]);
});

// TODO: Factor offset into duration check
/*const offsetIdx = this.snapshots.getTargetProperties().findIndex(prop => prop.name == "Offset");
// Factor offset into duration calculation
const scene = this.getGraphComponent(CVScene);
const bounds = scene.outs.boundingRadius.value;
const offsetIdx = this.snapshots.getTargetProperties().findIndex(prop => prop.name == "Offset");
const currentOffset = this.snapshots.getCurrentValues()[offsetIdx];
const offset = viewState.values[offsetIdx];
const dist = Math.sqrt(Math.pow(offset[0]-currentOffset[0],2)+Math.pow(offset[1]-currentOffset[1],2)+Math.pow(offset[2]-currentOffset[2],2));*/
const dist = Math.sqrt(Math.pow(offset[0]-currentOffset[0],2)+Math.pow(offset[1]-currentOffset[1],2)+Math.pow(offset[2]-currentOffset[2],2));

viewState.duration = /*dist > 0.01 ||*/ angleOffset > 0.01 ? 1.0 : 0; // don't animate if we are already there
viewState.duration = Math.min(Math.max(angleOffset/180, dist/bounds, 0.3),1.5); // max 1.5s, min 0.3s
}
}
6 changes: 3 additions & 3 deletions source/client/components/CVAssetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ class AssetLoadingManager extends LoadingManager
protected onLoadingError()
{
if (ENV_DEVELOPMENT) {
console.error(`Loading error`);
console.log(`Loading error`);
}

// trigger update
this._isBusy = false;
this._manager.ins.busy.set();
//this._isBusy = false;
//this._manager.ins.busy.set();
}
}
4 changes: 2 additions & 2 deletions source/client/components/CVAssetReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ export default class CVAssetReader extends Component
return this.fileLoader.getText(url);
}

async getModel(assetPath: string): Promise<Object3D>
async getModel(assetPath: string, {signal}:{signal?:AbortSignal}={}): Promise<Object3D>
{
const url = this.assetManager.getAssetUrl(assetPath);
return this.modelLoader.get(url);
return this.modelLoader.get(url, {signal});
}

async getGeometry(assetPath: string): Promise<BufferGeometry>
Expand Down
5 changes: 3 additions & 2 deletions source/client/components/CVAudioManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ export default class CVAudioManager extends Component
if(this.audioPlayer && this._narrationId) {
if(outs.narrationPlaying.value && this.activeId == this._narrationId) {
this.stop();
outs.narrationPlaying.setValue(false);
}
else if(!outs.narrationPlaying.value){
this.play(this._narrationId);
}
outs.narrationPlaying.setValue(!outs.narrationPlaying.value);
}
}
return true;
Expand Down Expand Up @@ -305,15 +305,16 @@ export default class CVAudioManager extends Component
this.setTimeElapsed(0);
}

outs.isPlaying.setValue(true);
this.audioView = this.audioViews[id];

this.initializeClip(id);

this.audioPlayer.play()
.then(() => {
this.activeId = id;
outs.isPlaying.setValue(true);
this.isPlaying = true;
outs.narrationPlaying.setValue(id == this.narrationId);
Object.keys(this.audioViews).forEach((key) => this.audioViews[key].requestUpdate());
this.analytics.sendProperty("Audio_Play", uri);
})
Expand Down
10 changes: 6 additions & 4 deletions source/client/components/CVEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ export default class CVEnvironment extends Component
}

this.assetReader.getSystemTexture("images/"+images[ins.imageIndex.value]).then(texture => {
this._texture = texture;
this._texture.mapping = EquirectangularReflectionMapping;
//this._texture.colorSpace = SRGBColorSpace;
this.sceneNode.scene.environment = this._texture;
if(this.node) {
this._texture = texture;
this._texture.mapping = EquirectangularReflectionMapping;
//this._texture.colorSpace = SRGBColorSpace;
this.sceneNode.scene.environment = this._texture;
}
});
this._currentIdx = ins.imageIndex.value;
}
Expand Down
83 changes: 59 additions & 24 deletions source/client/components/CVModel2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ export default class CVModel2 extends CObject3D
private _derivatives = new DerivativeList();
private _activeDerivative: Derivative = null;

/**
* Separate from activeDerivative because when switching quality levels,
* we want to keep the active model until the new one is ready
*/
private _loadingDerivative :Derivative = null;

private _visible: boolean = true;
private _boxFrame: Mesh = null;
private _boxFrame: Box3Helper = null;
private _localBoundingBox = new Box3();
private _prevPosition: Vector3 = new Vector3(0.0,0.0,0.0);
private _prevRotation: Vector3 = new Vector3(0.0,0.0,0.0);
Expand Down Expand Up @@ -306,7 +312,7 @@ export default class CVModel2 extends CObject3D
}
else if (ins.quality.changed) {
const derivative = this.derivatives.select(EDerivativeUsage.Web3D, ins.quality.value);
if (derivative && derivative !== this.activeDerivative) {
if (derivative) {
this.loadDerivative(derivative)
.catch(error => {
console.warn("Model.update - failed to load derivative");
Expand Down Expand Up @@ -375,7 +381,9 @@ export default class CVModel2 extends CObject3D
this.derivatives.clear();
this._activeDerivative = null;
for (let key in this._overlays) {
this._overlays[key].texture.dispose();
if(this._overlays[key].texture) {
this._overlays[key].texture.dispose();
}
}

super.dispose();
Expand Down Expand Up @@ -455,7 +463,7 @@ export default class CVModel2 extends CObject3D
boundingBox.min.fromArray(data.boundingBox.min);
boundingBox.max.fromArray(data.boundingBox.max);

this._boxFrame = new (Box3Helper as any)(boundingBox, "#009cde");
this._boxFrame = new Box3Helper(boundingBox, "#009cde");
this.addObject3D(this._boxFrame);
this._boxFrame.updateMatrixWorld(true);

Expand Down Expand Up @@ -627,18 +635,20 @@ export default class CVModel2 extends CObject3D
// helper function to update overlay map state
protected updateOverlayMaterial(texture: Texture, uri: string)
{
this.object3D.traverse(object => {
const material = object["material"];
if (material && material.isUberPBRMaterial) {
if(texture) {
texture.flipY = false;
material.enableOverlayAlpha(uri.endsWith(".jpg"));
if(this.object3D) {
this.object3D.traverse(object => {
const material = object["material"];
if (material && material.isUberPBRMaterial) {
if(texture) {
texture.flipY = false;
material.enableOverlayAlpha(uri.endsWith(".jpg"));
}
material.zoneMap = texture;
material.enableZoneMap(texture != null);
}
material.zoneMap = texture;
material.enableZoneMap(texture != null);
}
});
this.outs.overlayMap.setValue(this.ins.overlayMap.value);
});
this.outs.overlayMap.setValue(this.ins.overlayMap.value);
}
}

protected updateMaterial()
Expand Down Expand Up @@ -749,46 +759,68 @@ export default class CVModel2 extends CObject3D

// load sequence of derivatives one by one
return sequence.reduce((promise, derivative) => {
return promise.then(() => { this.loadDerivative(derivative)});
return promise.then(() => this.loadDerivative(derivative));
}, Promise.resolve());
}

/**
* Loads and displays the given derivative.
* @param derivative
*/
protected loadDerivative(derivative: Derivative): Promise<void>
protected async loadDerivative(derivative: Derivative): Promise<void>
{
if(!this.node || !this.assetReader) { // TODO: Better way to handle active loads when node has been disposed?
console.warn("Model load interrupted.");
return;
}
if(this._loadingDerivative && this._loadingDerivative != derivative) {
this._loadingDerivative.unload();
this._loadingDerivative = null;
}
if (this._activeDerivative == derivative){
return;
}
if(this._loadingDerivative == derivative) {
return new Promise(resolve=> this._loadingDerivative.on("load", resolve));
}

this._loadingDerivative = derivative;

return derivative.load(this.assetReader)
.then(() => {
if (!derivative.model || !this.node ||
(this._activeDerivative && derivative.data.quality != this.ins.quality.value)) {
if ( !derivative.model
|| !this.node
|| (this._activeDerivative && derivative.data.quality != this.ins.quality.value)
) {
//Either derivative is not valid, or we have been disconnected,
// or this derivative is no longer needed as it's not the requested quality
// AND we already have _something_ to display
derivative.unload();
return;
}

if(this._activeDerivative && this._activeDerivative == derivative){
//a race condition can happen where a derivative fires it's callback but it's already the active one.
return;
}

// set asset manager flag for initial model load
if(!this.assetManager.initialLoad && !this._activeDerivative) {
this.assetManager.initialLoad = true;
}

if (this._activeDerivative) {
this.removeObject3D(this._activeDerivative.model);
if(this._activeDerivative.model) this.removeObject3D(this._activeDerivative.model);
this._activeDerivative.unload();
}

this._activeDerivative = derivative;
this._loadingDerivative = null;
this.addObject3D(derivative.model);
this.renderer.activeSceneComponent.scene.updateMatrixWorld(true);

if (this._boxFrame) {
this.removeObject3D(this._boxFrame);
this._boxFrame.geometry.dispose();
this._boxFrame.dispose();
this._boxFrame = null;
}

Expand Down Expand Up @@ -855,8 +887,11 @@ export default class CVModel2 extends CObject3D

this.emit<IModelLoadEvent>({ type: "model-load", quality: derivative.data.quality });
//this.getGraphComponent(CVSetup).navigation.ins.zoomExtents.set();
})
.catch(error => Notification.show(`Failed to load model derivative: ${error.message}`));
}).catch(error =>{
if(error.name == "AbortError" || error.name == "ABORT_ERR") return;
console.error(error);
Notification.show(`Failed to load model derivative: ${error.message}`)
});
}

protected addObject3D(object: Object3D)
Expand Down
Loading

0 comments on commit 894eadc

Please sign in to comment.