Skip to content
Snippets Groups Projects
Commit cac7b8e4 authored by netpro2k's avatar netpro2k
Browse files

Cleanup image resizing code

parent 4ab036a4
No related branches found
No related tags found
No related merge requests found
...@@ -72,26 +72,6 @@ AFRAME.registerComponent("image-plus", { ...@@ -72,26 +72,6 @@ AFRAME.registerComponent("image-plus", {
contentType: { type: "string" } contentType: { type: "string" }
}, },
_fit(w, h) {
const ratio = (h || 1.0) / (w || 1.0);
const geo = this.el.geometry;
let width, height;
if (geo && geo.width) {
if (geo.height && ratio > 1) {
width = geo.width / ratio;
} else {
height = geo.height * ratio;
}
} else if (geo && geo.height) {
//TODO
width = geo.width / ratio;
} else {
width = Math.min(1.0, 1.0 / ratio);
height = Math.min(1.0, ratio);
}
return { width, height };
},
remove() { remove() {
const material = this.el.getObject3D("mesh").material; const material = this.el.getObject3D("mesh").material;
const texture = material.map; const texture = material.map;
...@@ -230,10 +210,6 @@ AFRAME.registerComponent("image-plus", { ...@@ -230,10 +210,6 @@ AFRAME.registerComponent("image-plus", {
texture = errorTexture; texture = errorTexture;
} }
const { width, height } = this._fit(
texture.image.videoWidth || texture.image.width,
texture.image.videoHeight || texture.image.height
);
const material = new THREE.MeshBasicMaterial(); const material = new THREE.MeshBasicMaterial();
material.side = THREE.DoubleSide; material.side = THREE.DoubleSide;
material.transparent = true; material.transparent = true;
...@@ -241,6 +217,12 @@ AFRAME.registerComponent("image-plus", { ...@@ -241,6 +217,12 @@ AFRAME.registerComponent("image-plus", {
material.needsUpdate = true; material.needsUpdate = true;
material.map.needsUpdate = true; material.map.needsUpdate = true;
const ratio =
(texture.image.videoHeight || texture.image.height || 1.0) /
(texture.image.videoWidth || texture.image.width || 1.0);
const width = Math.min(1.0, 1.0 / ratio);
const height = Math.min(1.0, ratio);
const geometry = new THREE.PlaneGeometry(width, height, 1, 1); const geometry = new THREE.PlaneGeometry(width, height, 1, 1);
this.mesh = new THREE.Mesh(geometry, material); this.mesh = new THREE.Mesh(geometry, material);
this.el.setObject3D("mesh", this.mesh); this.el.setObject3D("mesh", this.mesh);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment