1

他のプリミティブで構成されるフレーム内のプリミティブを登録しています。しかし、これらの内部プリミティブを個別にスケーリングおよび配置したいと考えています。しかし、位置自体はコンポーネントであるため、これらの内部プリミティブには位置がないため、移動できません。

登録したいプリミティブの一部であるプリミティブのコンポーネントに値を設定するにはどうすればよいですか?

AFRAME.registerPrimitive('a-svrbutton', {
  defaultComponents: {
    geometry: {
      primitive: 'box',
      height: 1.5,
      depth: 0.2,
      width: 3.5
    },
    material: {
      opacity: 1.0,
      transparent: true,
      side: 'Double',
      color: '#8450ff'
    },
    position: {
      x: 0,
      y: 0,
      z: -5
    },
    'bmfont-text': {
      text: 'hola',
      color: '#ffffff'
    },

  },
  mappings: {
    height: 'geometry.height',
    width: 'geometry.width',
    depth: 'geometry.depth',
    color: 'material.color',
    opacity: 'material.opacity',
    position: 'position'
  }
});
<script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>

<a-scene>
  <a-svrbutton id="mybutton" position="0 0 -5"></a-svrbutton>
</a-scene>

上記のスニペットを実行するには、ブラウザーが WebVR をサポートしていることを確認してください。

デフォルトの「コンポーネント」bmfont-text のデフォルト位置として、任意の xy および z として定義したいと考えています。しかし、この「プリミティブ」には位置コンポーネント自体がないため、できません。どうやってやるの?

4

2 に答える 2

2

通常、プリミティブは 1 つ以上のコンポーネントの省略形であり、のプリミティブではありません。そのため、あなたがしていることを誤解している可能性があります。もしそうなら、質問にサンプル コードを追加していただけますか?

通常、プリミティブにそのコンポーネントがまだない場合でも、無関係なコンポーネントをプリミティブに追加できます。

<a-text text="Hello World;" position="0 0 -5"></a-text>

<a-text />それが機能しない場合は、プリミティブ バージョンではなく bmfont をコンポーネントとして使用することをお勧めします。

<a-entity bmfont-text="text: Hello World;" position="0 0 -5"></a-entity>

A-Frame v0.3.0 の時点で、プリミティブにいくつかのバグがあるため、コンポーネントと mixin の信頼性が向上する可能性があります。

于 2016-09-16T13:58:28.807 に答える
1

1 つの方法は、それらを 2 つの別個のエンティティにすることです。

<a-entity>
  <a-srvbutton></a-srvbutton>
  <a-text></a-text>
</a-entity>

それとも bmfont テキストをラップするラッパー コンポーネントを作成しますか?

AFRAME.registerComponent('bmfont-text-wrapper', {
  schema: {
    textPosition: {type: 'vec3'},
    text: {type: 'string'}
  },

  init: function () {
    var text = document.createElement('a-entity');
    text.setAttribute('bmfont-text', this.data.text);
    text.setAttribute('position', this.data.textPosition);
    this.el.appendChild(text);
  }
});

次に、マッピングを追加します。

于 2016-09-16T22:39:24.130 に答える