Skip to content

Instantly share code, notes, and snippets.

@superdump
Created March 18, 2017 21:57
Show Gist options
  • Save superdump/398e638615da278b6f9339452bbd6a6a to your computer and use it in GitHub Desktop.
Save superdump/398e638615da278b6f9339452bbd6a6a to your computer and use it in GitHub Desktop.
AFRAME.registerComponent('spherecube', {
schema: {
color: {type: 'color', default: '#FFF'},
radius: {type: 'number', default: '1'},
segments: {type: 'int', default: '8'},
},
init: function() {
const data = this.data;
const el = this.el;
this.geometry = new SphereCubeBufferGeometry(data.radius, data.segments);
this.material = new THREE.MeshBasicMaterial();
this.mesh = new THREE.Mesh(this.geometry, this.material);
el.setObject3D('mesh', this.mesh);
},
remove: function() {
this.el.removeObject3D('mesh');
},
});
AFRAME.registerPrimitive('a-videospherecube', AFRAME.utils.extendDeep({}, AFRAME.primitives.getMeshMixin(), {
defaultComponents: {
spherecube: {
radius: 1,
segments: 8,
},
material: {
color: '#FFF',
shader: 'flat',
},
scale: '-1 1 1',
},
mappings: {
color: 'material.color',
radius: 'spherecube.radius',
segments: 'spherecube.segments',
src: 'material.src',
},
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment