aframevr / aframe-inspector

:mag: Visual inspector tool for A-Frame. Hit *<ctrl> + <alt> + i* on any A-Frame scene.
https://aframe.io/aframe-inspector/examples/
MIT License
654 stars 201 forks source link

"Copy Entity HTML to Clipboard" does not work in the example #409

Closed jsantell closed 7 years ago

jsantell commented 7 years ago

Haven't dug in why it's only some entities that throw errors, but in the built in example (and some entities in my own scenes and the aframe examples), a few entities throw when copying:

<a-scene />

Uncaught TypeError: Cannot read property 'length' of null
    at removeDefaultAttributes (entity.js:156)

<a-box />

Uncaught TypeError: Cannot read property 'getAttribute' of null
    at Object.selectorStringify [as stringify] 

Have also seen errors with addEventListener and removeChild when attempting to copy, but on other entities it works fine.

fernandojsg commented 7 years ago

@dmarcos could you take a look at it? It looks like a problem on getClipboardRepresentation when calling flushToDOM here: https://github.com/aframevr/aframe-inspector/blob/master/src/actions/entity.js#L144

fernandojsg commented 7 years ago

I've just updated to the latest aframe in the example and it seems to fix some of the issues, or at least modify the error :) So far it works on entities that doesn't have maps, but in the ones that have maps like a-box or floor it throws:

aframe.min.js:275 Uncaught TypeError: Cannot read property 'systems' of undefined
    at Object.module.exports.updateMap (aframe.min.js:275)
    at t.init (aframe.min.js:240)
    at i.updateShader (aframe.min.js:79)
    at i.update (aframe.min.js:79)
    at i.updateProperties (aframe.min.js:145)
    at HTMLElement.value (aframe.min.js:137)
    at HTMLElement.value (aframe.min.js:137)
    at HTMLElement.value (aframe.min.js:137)
    at HTMLElement.value (aframe.min.js:143)
    at HTMLElement.value (aframe.min.js:143)
dmarcos commented 7 years ago

This one is trickier than I thought and I'm a bit surprised we did not see the problem before. The issue is that updateMap relies on sceneEl being available. The Copy Entity HTML to Clipboard feature clones the selected entity to avoid undesired modifications and manipulates it to remove default and mixed in values. The cloned entity is not part of a-scene so updateMap does not find the reference it needs. The problem is that updateMap is invoked from the update method which should not ever be called for a not yet loaded entity. I have to investigate a bit more to figure out a proper solution.

dmarcos commented 7 years ago

I fixed this on https://github.com/aframevr/aframe/pull/2250. Try https://aframe.io/aframe/dist/aframe-master.js and close the issue if the bug is gone.

jsantell commented 7 years ago

Firing the copy for the <a-box> element with the new aframe master causes a el.sceneEl is undefined in aframe's updateMap and the <a-scene> element throws:

TypeError: el.getAttribute(...) is null aframe-inspector.js:37000:12
removeDefaultAttributes http://0.0.0.0:3333/dist/aframe-inspector.js:37000:12
getClipboardRepresentation http://0.0.0.0:3333/dist/aframe-inspector.js:36985:4
text http://0.0.0.0:3333/dist/aframe-inspector.js:39532:20
onClick http://0.0.0.0:3333/dist/aframe-inspector.js:38782:28
listenClick/this.listener< http://0.0.0.0:3333/dist/aframe-inspector.js:38767:29
listener/< http://0.0.0.0:3333/dist/aframe-inspector.js:39400:14

I'll dig more into this later

dmarcos commented 7 years ago

@jsantell <a-box> is working for me.

There's another problem with <a-scene> that https://github.com/aframevr/aframe-inspector/pull/418 fixes

dmarcos commented 7 years ago

I believe everything should be working now.

fernandojsg commented 7 years ago

@jsantell it's working here too, the problem was that it was an error deploying the latest aframe-master.js now it's deployed correctly and it fixes the issue.

dmarcos commented 7 years ago

Reopen. It seems that this feature is broken again.

dmarcos commented 7 years ago

Steps to reproduce:

  1. Go to https://aframe.io/aframe-inspector/example/#
  2. Click on the floor entity and copy to clipboard

The obtained result is: <a-entity id="floor" geometry="mergeTo:null;primitive:cylinder;height:0.2;radius:12" material="repeat:[object Object];color:#fafafa;metalness:0.2;normalScale:{&quot;x&quot;:1,&quot;y&quot;:1};roughness:0.1;src:assets/textures/grasslight-big.jpg"></a-entity>

Material is not properly serialized material="repeat:[object Object];color:#fafafa;metalness:0.2;normalScale:{&quot;x&quot;:1,&quot;y&quot;:1};roughness:0.1;src:assets/textures/grasslight-big.jpg"

repeat should be repeat: 1 1 and normalScale normalScale: 1 1

fernandojsg commented 7 years ago

It seems that https://github.com/aframevr/aframe/pull/2357 fixed the [object object] issue, but the &quot; is still there:

<a-entity id="floor" geometry="mergeTo:null;primitive:cylinder;height:0.2;radius:12" material="repeat:50 20;color:#fafafa;metalness:0.2;normalScale:{&quot;x&quot;:1,&quot;y&quot;:1};roughness:0.1;src:https://aframe.io/sample-assets/assets/images/terrain/grasslight-big.jpg"></a-entity>

/cc @dmarcos @delapuente

fernandojsg commented 7 years ago

I've just noticed that if you click on an entity and modify the common attributes position, rotation and/or scale they won't appear on the clipboard representation :\

delapuente commented 7 years ago

I'll take a look.

machenmusik commented 7 years ago

mchen [12:55 PM] with latest inspector, when i create an entity then click the button to copy entity HTML to clipboard, position and scale are not coming across (rotation either, but here I didn't change)... and a few unchanged / superfluous properties are included (mergeTo, normalScale) <a-entity position="" scale="" id="endtable" geometry="mergeTo:null;depth:10;height:0.1;width:10" material="opacity:0.5;normalScale:{&quot;x&quot;:1,&quot;y&quot;:1}"></a-entity>

delapuente commented 7 years ago

That's the expected behaviour since you are representing double quotes inside double quotes. Try this code to check:

var html = '<a-entity position="" scale="" id="endtable" geometry="mergeTo:null;depth:10;height:0.1;width:10" material="opacity:0.5;normalScale:{&quot;x&quot;:1,&quot;y&quot;:1}"></a-entity>';
var container = document.createElement('div');
container.innerHTML = html;
var entity = container.querySelector('a-entity');
console.log(entity.getAttribute('material')) // outputs opacity:0.5;normalScale:{"x":1,"y":1}

Problem is that normal scale should not be represented that way if it is an A-Frame vec2 type. Let's keep this bug as solved and see what happens in A-Frame.

machenmusik commented 7 years ago

no, big problem in that case was actually that position and scale were not correctly included in export, and that mergeTo and normalScale were default so should have been absent

delapuente commented 7 years ago

Noted. That's a different problem. Let's open another bug for that.

dmarcos commented 7 years ago

Closing this. Follow up issues https://github.com/aframevr/aframe-inspector/issues/453 and https://github.com/aframevr/aframe-inspector/issues/452