Skip to content

Commit

Permalink
Fix panels disappearing when selecting a-videosphere entity
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Jun 12, 2024
1 parent fcff3a6 commit 449fdce
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/editor/components/widgets/TextureWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export default class TextureWidget extends React.Component {

function getTextureFromSrc(src) {
for (var hash in AFRAME.INSPECTOR.sceneEl.systems.material.textureCache) {
if (JSON.parse(hash).src === src) {
// The key in textureCache is not always a json.
// For example <a-videosphere src="#video"> gives a "video" key in textureCache.
// So we check for '{' before using JSON.parse here.
if (hash[0] === '{' && JSON.parse(hash).src === src) {
return AFRAME.INSPECTOR.sceneEl.systems.material.textureCache[hash];
}
}
Expand All @@ -141,8 +144,10 @@ export default class TextureWidget extends React.Component {
var url;
var isAssetHash = value[0] === '#';
var isAssetImg = value instanceof HTMLImageElement;
var isAssetVideo = value instanceof HTMLVideoElement;
var isAssetImgOrVideo = isAssetImg || isAssetVideo;

if (isAssetImg) {
if (isAssetImgOrVideo) {
url = value.src;
} else if (isAssetHash) {
url = getUrlFromId(value);
Expand All @@ -154,10 +159,10 @@ export default class TextureWidget extends React.Component {

var texture = getTextureFromSrc(value);
var valueType = null;
valueType = isAssetImg || isAssetHash ? 'asset' : 'url';
if (texture) {
valueType = isAssetImgOrVideo || isAssetHash ? 'asset' : 'url';
if (!isAssetVideo && texture) {
texture.then(paintPreview);
} else if (url) {
} else if (!isAssetVideo && url) {
// The image still didn't load
var image = new Image();
image.addEventListener(
Expand All @@ -173,7 +178,7 @@ export default class TextureWidget extends React.Component {
}

this.setState({
value: isAssetImg ? '#' + value.id : value,
value: isAssetImgOrVideo ? '#' + value.id : value,
valueType: valueType,
url: url
});
Expand Down

0 comments on commit 449fdce

Please sign in to comment.