Skip to content

Instantly share code, notes, and snippets.

@heyMP
Last active November 26, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heyMP/3848581a97af6814331dcd4b2f14a493 to your computer and use it in GitHub Desktop.
Save heyMP/3848581a97af6814331dcd4b2f14a493 to your computer and use it in GitHub Desktop.
Clone geometry and meshes a-frame
import registerComponent from '../utils/registerComponent';
const bottle = {
schema: {
id: { type: 'string' }
},
init: function () {
// create the label entity
const labelEl = document.createElement('a-entity')
labelEl.className = 'label'
this._labelEl = this.el.appendChild(labelEl)
this.createLabel()
},
/**
* This gets the full mesh from gltf object that's already been loaded.
*
*/
createLabel: function () {
// get the mesh
const mesh = this.el.getObject3D('mesh')
const label = this._labelEl
if (mesh && label) {
// you can traverse the mesh to get to all of the 'layers'
mesh.traverse(object => {
if (object.name === '3MHCl') {
const newMesh = object.clone()
newMesh.material = new THREE.MeshBasicMaterial({ color: 0x000000, wireframe: false })
label.setObject3D('mesh', newMesh)
}
})
}
/**
* recursively try the create label again
*/
else {
setTimeout(this.createLabel.bind(this), 10)
}
}
}
export default registerComponent('bottle', bottle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment