Skip to content

Commit

Permalink
fix for image transparencies and other general enhancments
Browse files Browse the repository at this point in the history
  • Loading branch information
MetaverseUnknower committed Jan 22, 2023
1 parent 5c627a2 commit e7c623a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 58 deletions.
35 changes: 3 additions & 32 deletions src/classes/StoredEntity.ts
Expand Up @@ -79,7 +79,7 @@ export class StoredEntityConfig {
}
}

export class StoredEntityInstance extends Entity implements ITransform {
export class StoredEntityInstance extends Entity {
id: string;
show: boolean;
name: string;
Expand All @@ -91,6 +91,7 @@ export class StoredEntityInstance extends Entity implements ITransform {
scale: TTransform;
rotation: TTransform;
clickEvent?: TClickEvent;
defaultClickEvent?: TClickEvent;
modifiedTransform: { position: TTransform; scale: TTransform; rotation: TTransform };

constructor(_material: StoredEntityMaterial | StoredEntityConfig, _instance: TEntityInstanceConfig) {
Expand All @@ -104,37 +105,7 @@ export class StoredEntityInstance extends Entity implements ITransform {
this.scale = _instance.scale;
this.rotation = _instance.rotation;
this.materialId = _material.id;
this.clickEvent = _instance.clickEvent;
}

updateParent: CallableFunction = (_parent: string) => {
const instanceParent = getEntityByName(_parent);
this.setParent(instanceParent);
};

updateTransform: CallableFunction = (_transform: TranformConstructorArgs) => {
this.addComponentOrReplace(new Transform(_transform));
};

updateClickEvent: CallableFunction = (_clickEvent: TClickEvent) => {
const clickEventType = _clickEvent.type,
options = { showFeedback: _clickEvent.showFeedback, hoverText: _clickEvent.hoverText },
hasClickEvent = this.getComponentOrNull(OnPointerDown);

let clickAction;

if (clickEventType == EClickEventType.NONE && hasClickEvent) {
this.removeComponent(OnPointerDown);
} else if (clickEventType == EClickEventType.EXTERNAL && _clickEvent.externalLink) {
clickAction = openExternalURL(_clickEvent.externalLink);
} else if (clickEventType == EClickEventType.MOVE && _clickEvent.moveTo) {
clickAction = movePlayerTo(_clickEvent.moveTo.position, _clickEvent.moveTo.cameraTarget);
} else if (clickEventType == EClickEventType.TELEPORT && _clickEvent.teleportTo) {
clickAction = teleportTo(_clickEvent.teleportTo);
} else if (clickEventType == EClickEventType.SOUND && _clickEvent.sound) {
clickAction = new Sound(_clickEvent.sound);
} else if (clickEventType == EClickEventType.STREAM && _clickEvent.sound) {
clickAction = new Stream(_clickEvent.sound);
}
};

}
51 changes: 30 additions & 21 deletions src/classes/StoredImage.ts
Expand Up @@ -108,12 +108,12 @@ export class StoredImageMaterial extends Material implements ITexture, IEmission
this.imageLink = url;
}

const texture = new Texture(this.imageLink, { hasAlpha: this.isTransparent });
const texture = new Texture(this.imageLink, {hasAlpha: this.isTransparent});
this.albedoTexture = texture;
this.emissiveTexture = texture;
this.alphaTexture = texture;
if (this.isTransparent) {
this.transparencyMode = TransparencyMode.ALPHA_BLEND;
this.transparencyMode = TransparencyMode.ALPHA_TEST;
} else {
this.transparencyMode = TransparencyMode.OPAQUE;
}
Expand All @@ -131,10 +131,7 @@ export class StoredImageMaterial extends Material implements ITexture, IEmission
updateClickEvent: CallableFunction = (clickEvent: TClickEvent) => {
this.clickEvent = clickEvent;
[...this.instanceIds].forEach((instanceId: string) => {
if (!clickEvent) {
return;
}
imageInstances[instanceId].updateClickEvent(clickEvent);
imageInstances[instanceId].updateDefaultClickEvent(this.clickEvent);
});
};

Expand Down Expand Up @@ -179,14 +176,15 @@ export class StoredImageInstance extends StoredEntityInstance implements ITransf
this.rotation = _instance.rotation;
this.materialId = _material.id;
this.show = _instance.show;
this.clickEvent = _instance.clickEvent || _material.clickEvent;
this.clickEvent = _instance.clickEvent;
this.defaultClickEvent = _material.clickEvent;
imageInstances[this.id] = this;
const shape = new PlaneShape();
shape.withCollisions = typeof _instance.withCollisions === "boolean" ? _instance.withCollisions : _material.withCollisions;
this.addComponent(shape);
this.addComponent(_material);
this.updateTransform(this.position, this.scale, this.rotation);
this.updateClickEvent(this.clickEvent);
this.updateDefaultClickEvent(_material.clickEvent);

if (this.parent && this.show && !this.customRendering) {
this.updateParent(this.parent);
Expand Down Expand Up @@ -242,8 +240,8 @@ export class StoredImageInstance extends StoredEntityInstance implements ITransf
new Transform({
position: new Vector3(position.x, position.y, position.z),
scale: new Vector3(scale.x, scale.y, scale.z),
rotation: Quaternion.Euler(rotation.x, rotation.y, rotation.z),
}),
rotation: Quaternion.Euler(rotation.x, rotation.y, rotation.z)
})
);
};

Expand Down Expand Up @@ -278,17 +276,28 @@ export class StoredImageInstance extends StoredEntityInstance implements ITransf
}
};

updateClickEvent: CallableFunction = (clickEvent: TClickEvent) => {
if (!clickEvent) {
return;
updateDefaultClickEvent: CallableFunction = (newDefaultClickEvent: TClickEvent) => {
this.defaultClickEvent = newDefaultClickEvent;
this.updateClickEvent();
};

updateClickEvent: CallableFunction = (newClickEvent?: TClickEvent) => {
if (typeof newClickEvent !== "undefined") {
this.clickEvent = newClickEvent;
}

if (this.clickEvent && this.clickEvent.synced) {
this.clickEvent = this.defaultClickEvent;
}

const clickEvent = this.clickEvent;

let pointerDownEvent,
showFeedback = clickEvent.showFeedback,
hoverText = clickEvent.hoverText,
showFeedback = clickEvent && clickEvent.showFeedback,
hoverText = clickEvent && clickEvent.hoverText,
instanceId = this.id;

if (!imageInstances[instanceId]) {
if (!clickEvent || !imageInstances[instanceId]) {
return;
}

Expand All @@ -312,7 +321,7 @@ export class StoredImageInstance extends StoredEntityInstance implements ITransf
openExternalURL(clickEvent.externalLink);
this.trackClickEvent(clickEvent, `click-event-(external-link)-${this.customId || this.id}`);
},
{ showFeedback, hoverText },
{ showFeedback, hoverText }
);
break;
case EClickEventType.SOUND: //play a sound
Expand All @@ -323,16 +332,16 @@ export class StoredImageInstance extends StoredEntityInstance implements ITransf
source.playOnce();
this.trackClickEvent(clickEvent, `click-event-(sound)-${this.customId || this.id}`);
},
{ showFeedback, hoverText },
{ showFeedback, hoverText }
);
break;
case EClickEventType.MOVE: // move player
pointerDownEvent = new OnPointerDown(
() => {
movePlayerTo(clickEvent.moveTo.position, clickEvent.moveTo.cameraTarget);
movePlayerTo(clickEvent.moveTo.position, (clickEvent.moveTo.setCameraTarget ? clickEvent.moveTo.cameraTarget : null));
this.trackClickEvent(clickEvent, `click-event-(move-player)-${this.customId || this.id}`);
},
{ showFeedback, hoverText },
{ showFeedback, hoverText }
);
break;
case EClickEventType.TELEPORT: // teleport player
Expand All @@ -341,7 +350,7 @@ export class StoredImageInstance extends StoredEntityInstance implements ITransf
teleportTo(clickEvent.teleportTo);
this.trackClickEvent(clickEvent, `click-event-(teleport-player)-${this.customId || this.id}`);
},
{ showFeedback, hoverText },
{ showFeedback, hoverText }
);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/classes/StoredVideo.ts
Expand Up @@ -409,7 +409,7 @@ export class StoredVideoCheckSystem implements ISystem {
};

update(dt: number) {
if (this.dtDelay > 30) {
if (this.dtDelay > 100) {
this.dtDelay = 0;
return;
} else if (this.dtDelay > 0) {
Expand Down Expand Up @@ -525,9 +525,9 @@ export class StoredVideoCheckSystem implements ISystem {
this.videoStatus = data.videoStatus;
this.videoLength = Math.floor(data.totalVideoLength);
this.timer = Math.ceil(data.currentOffset);
log(`VLM - this.video.textureMode == ${EVideoSourceTypes.LIVE}`);
log(`VLM - ${data.videoClipId}`);
log(`VLM - ${this.videoStatus} ${this.videoLength} ${this.timer}`);
// log(`VLM - this.video.textureMode == ${EVideoSourceTypes.LIVE}`);
// log(`VLM - ${data.videoClipId}`);
// log(`VLM - ${this.videoStatus} ${this.videoLength} ${this.timer}`);
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/sceneData.ts
Expand Up @@ -9,6 +9,9 @@ export const updateSceneData = (sceneDataConfig: TSceneData) => {
};

export const updateSceneFeatures = (sceneFeaturesConfig: TSceneFeatures) => {
if (!sceneFeaturesConfig) {
return;
}
Object.keys(sceneFeaturesConfig).forEach((feature: string) => {
sceneFeatures[feature] = sceneFeaturesConfig[feature];
});
Expand Down
3 changes: 2 additions & 1 deletion src/types/ClickEvent.ts
Expand Up @@ -16,8 +16,9 @@ export type TClickEvent = {
hoverText: string;
externalLink?: string;
sound?: string;
moveTo?: { cameraTarget: TTransform; position: TTransform };
moveTo?: { cameraTarget: TTransform; position: TTransform, setCameraTarget: boolean };
teleportTo?: string;
hasTracking?: boolean;
trackingId?: string;
synced?: boolean;
};

0 comments on commit e7c623a

Please sign in to comment.