Last active
November 26, 2018 19:04
-
-
Save heyMP/3848581a97af6814331dcd4b2f14a493 to your computer and use it in GitHub Desktop.
Clone geometry and meshes a-frame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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