Skip to content

Instantly share code, notes, and snippets.

@spiritbroski
Created March 18, 2021 23:32
Show Gist options
  • Select an option

  • Save spiritbroski/a78dc1ca469228350b01ee6900394479 to your computer and use it in GitHub Desktop.

Select an option

Save spiritbroski/a78dc1ca469228350b01ee6900394479 to your computer and use it in GitHub Desktop.
<template id="interactable-iframe-media">
<a-entity
class="interactable"
is-remote-hover-target
hoverable-visuals
tags="isHandCollisionTarget: true; offersHandConstraint: true; offersRemoteConstraint: true; inspectable: true;"
body-helper="type: dynamic; mass: 1; collisionFilterGroup: 1; collisionFilterMask: 31;"
matrix-auto-update
shape-helper="type: box"
set-unowned-body-kinematic
floaty-object="modifyGravityOnRelease: true; autoLockOnLoad: true; gravitySpeedLimit: 0; reduceAngularFloat: true;"
set-yxz-order
destroy-at-extreme-distances
matrix-auto-update
loader="loadedEvent: page-thumbnail-loaded"
>
</a-entity>
</template>
import { resolveUrl, createImageTexture } from "../utils/media-utils";
import { proxiedUrlFor } from "../utils/media-url-utils";
AFRAME.registerComponent("page-thumbnail", {
schema: {
src: { type: "string" }
},
init: function() {
this.updateThumbnail = this.updateThumbnail.bind(this);
this.move = () => {
console.log("dsadas")
};
this.el.object3D.addEventListener("ui-mousemove", this.move);
},
update(prevData) {
if (this.data.src !== prevData.src) {
this.updateThumbnail();
}
},
updateThumbnail: async function updateThumbnail() {
// if (this.el.object3DMap.mesh) {
// this.el.removeObject3D("mesh");
// }
const src = this.data.src;
const result = await resolveUrl(src);
const thumbnailUrl = result?.meta?.thumbnail;
if (!thumbnailUrl) {
throw Error("No thumbnail found");
}
const corsProxiedThumbnailUrl = proxiedUrlFor(thumbnailUrl);
const texture = await createImageTexture(corsProxiedThumbnailUrl);
const geometry = new THREE.PlaneBufferGeometry(1.6, 0.9, 1, 1, texture.flipY);
const material = new THREE.MeshBasicMaterial({ map: texture, side: THREE.DoubleSide });
const mesh = new THREE.Mesh(geometry, material);
this.el.setObject3D("mesh", mesh);
this.el.emit("page-thumbnail-loaded");
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment