0

Here is a Three.js Example from stemkoski, now I want to use this Texture-Animation plane or box in A-frame page, how can I Combine it.

A-frame Version: 0.9.0

I couldn't find any examples.

3
  • entire page chunks or just the animation material ? Commented Aug 18, 2019 at 13:14
  • Yes I just want the animation material in A-frame Commented Aug 18, 2019 at 13:23
  • So sorry to forgot the source code link Commented Aug 18, 2019 at 13:47

1 Answer 1

2

When integrating three.js pieces into aframe, it's recommended to use custom components. Here's a simple example:

js

AFRAME.registerComponent('foo', {

  // this is called upon initialization
  init: function() {
     // we'll need this later on for updating the animation
     this.animator = null

     // wait until the component is loaded
     this.el.addEventListener('loaded', e => {
            // copied straight from stemkoski's code:
            var runnerTexture = new THREE.ImageUtils.loadTexture( 'images/run.png' );
            this.animator = new TextureAnimator( runnerTexture, 10, 1, 10, 75 ); 

            // apply the texture to our element
            let mesh = this.el.getObject3D('mesh')
            mesh.material.map = runnerTexture 
            mesh.material.needsUpdate = true
     })
  },

  // this is called before each render loop
  tick: function(time, delta) {
      // update only if animator was created
      if (!this.animator) return
      this.animator.update(1000 * delta);
  }
})

HTML:

<a-plane foo></a-plane>

glitch here. To make it work with a glitch i had to preload the image with a-assets due to cors issues.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you first I tried with a very sample example link,looks the texture not working, I am newbie for A-frame and three.js
@zcai i've added a glitch

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.