0

'G.objects.map().on()' 仅由放置数据的浏览器触发。其他浏览器无法获得任何有关它的事件。

当我单击橙色按钮时,会创建一个随机对象。但它适用于一个浏览器。不同步。请检查这个 gif。

1

另一个节点的 .on() 类似位置被很好地触发。

位置

枪的版本 0.2019.627。

这是我的代码。

放入数据的一部分

 let object = {
            id: S.myAlias + Math.floor( Math.random()*1000 ).toString(16),
            parent: 'scene',
            tagName: 'a-entity',
            attributes: {
                geometry : {
                    primitive: geometries[Math.floor(Math.random()* geometries.length)]  // random geometries
                },
                color: '#'+toHex(rgb),
                position : {
                    x : Math.random() * 16 - 8,
                    y : Math.random() * 10 - 3,
                    z : Math.random() * 25 - 25,
                },
                rotation: {
                    x : Math.random() * 2 * Math.PI,
                    y : Math.random() * 2 * Math.PI,
                    z : Math.random() * 2 * Math.PI

                },
                'transform-controls' : { activated: false }
            }
        };

        G.objects.get( object.id ).put(object); // put!!!!!
        G.scene.get('children').set( G.objects.get(object.id) )

部分订阅数据

G.objects.map().on(  function createEntity(data, key){
    console.log('come on!!!!!!'); 

    let el = checkElement(key);
    this.get('attributes').once().map().once(function updateAttributes(data, key){
        // el.setAttribute(key, data);
        switch (key) {
            case 'geometry': this.once( updateGeometry );
                break;
            case 'color': this.once( updateColor );
                break;
            case 'transform-controls': this.once( updateTransformControls );
                break;
            default: el.setAttribute(key, data);
        }
    });
 });

我怎样才能让每个连接的浏览器都收到它的事件?

4

1 回答 1

0

它在更改部分放置数据的方式后起作用。

let obj = G.objects.get( object.id );
obj.put(object);

let obj = G.objects.get( object.id );
obj.get('id').put(object.id);
obj.get('parent').put(object.parent);
obj.get('tagName').put('a-entity');
obj.get('attributes').get('geometry').put({primitive: object.attributes.geometry.primitive});
obj.get('attributes').get('material').put({color: object.attributes.material.color});
obj.get('attributes').get('position').put(object.attributes.position);
obj.get('attributes').get('rotation').put(object.attributes.rotation);
obj.get('attributes').get('transform-controls').put(object.attributes["transform-controls"]);

于 2019-07-22T11:59:11.037 回答