import React, { Component } from 'react' import ReactDOM from 'react-dom' import { names, faces } from './faces' import * as markers from './markers' import * as mesh from './mesh' import './editor.css' import * as offsets from ' ./all_faces_offsets' const origin = { x: -0.037, y: 0.066, z: -0.038, scale: 0.00008 } class Editor extends Component { state = { name: "", position: { ...origin }, mesh: null, } constructor() { super() setTimeout(() => { this.update('brad_smith_1_0') }, 100 ) } update(name) { console.log(name) this.setState({ name }) const face = faces[name] markers.swap(face) mesh.load(name).then(geometry => { let meshes = mesh.createFaceMeshes(geometry) setTimeout(() => { meshes.solid.material.opacity = 1 mesh.removeMesh('blank') mesh.removeMesh('wireframe') const savedPosition = offsets[name] this.setState({ mesh: meshes.solid, geometry: { x: meshes.solid.position.x, y: meshes.solid.position.y, z: meshes.solid.position.z, scale: meshes.solid.scale.x }, position: { ...(savedPosition || origin) } }, () => this.updatePosition()) }, 10) }) } updatePosition() { const { geometry, position, mesh } = this.state console.log(geometry, position) // window['m'] = mesh mesh.material.opacity = 1 mesh.position.setX(geometry.x + position.x) mesh.position.setY(geometry.y + position.y) mesh.position.setZ(geometry.z + position.z) mesh.scale.setX(geometry.scale + position.scale) mesh.scale.setY(geometry.scale + position.scale) mesh.scale.setZ(geometry.scale + position.scale) } save() { console.log(JSON.stringify({ [this.state.name]: this.state.position })) } render() { return (
) } } ReactDOM.render(, document.querySelector('.links')) document.querySelector('.teaser').remove()