Changeset 911 for js/human_3d_alignment/src/widgets
- Timestamp:
- 04/18/20 20:18:36 (5 years ago)
- Location:
- js/human_3d_alignment/src/widgets
- Files:
-
- 5 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
js/human_3d_alignment/src/widgets/similviewer.jsx
r881 r911 3 3 import React from 'react'; 4 4 import ReactDOM from 'react-dom'; 5 import * as THREE from 'three'; 5 6 import Sviewer from '../visualization/sviewer'; 6 7 import { Md3dRotation, MdYoutubeSearchedFor } from 'react-icons/lib/md'; 7 import GenotypeParser from '../utils/genotypeparser';8 import _ from 'lodash';9 import * as THREE from 'three';10 8 11 9 /** … … 24 22 rezoom: true, 25 23 valid: true, 26 clicked: false 24 clicked: false, 25 controlMode: 'translate', 26 round: 0 27 27 }; 28 28 this.start = this.start.bind(this); … … 38 38 let temp2 = ReactDOM.findDOMNode(this.mount).parentNode; 39 39 this.viewer = new Sviewer(temp2.clientWidth, temp2.clientHeight, temp); 40 if (this.model) {41 //Module.destroy(this.model);42 }43 this.model = GenotypeParser.getModelFromGenotype("X(X,X)");44 this.model2 = GenotypeParser.getModelFromGenotype("XX");45 this.viewer.loadMeshesFromModel(this.model, this.model2);46 40 this.viewer.setAutoRotate(this.state.autorotate); 47 41 this.viewer.setRezoom(this.state.rezoom); 48 //this.elementspicker = new ElementsPicker(this.viewer.scene, this.viewer.camera.getPerspectiveCamera()); 42 49 43 this.renderScene = this.viewer.renderScene.bind(this.viewer); 50 44 this.lastw = temp2.clientWidth; … … 94 88 this.viewer.renderer, 95 89 this.viewer.camera.getPerspectiveCamera()); 90 91 if (!this.props.blockView) { 92 93 if (this.props.round != this.state.round) { 94 this.setState({ round: this.props.round }, function() { 95 console.log(`Round in sim: `, this.state.round); 96 }); 97 this.viewer.add2Genotypes(this.props.genotype1, this.props.genotype2); 98 this.viewer.addLines(this.props.selected1, this.props.selected2); 99 } 100 if (this.props.controlMode != this.state.controlMode) { 101 this.setState({ controlMode: this.props.controlMode }, function() { 102 console.log('Control mode: ', this.state.controlMode); 103 this.viewer.setMode(this.state.controlMode); 104 }) 105 } 106 if (this.viewer.selected1 != this.props.selected1) { 107 this.viewer.selected1 = []; 108 this.viewer.selected1 = this.props.selected1; 109 } 110 if (this.viewer.selected2 != this.props.selected2) { 111 this.viewer.selected2 = []; 112 this.viewer.selected2 = this.props.selected2; 113 } 114 if (this.props.round == this.state.round) { 115 this.viewer.addText(); 116 this.viewer.addLines(this.props.selected1, this.props.selected2); 117 } else { 118 this.viewer.clearView(); 119 } 120 } 96 121 } 97 122 … … 107 132 */ 108 133 switchRezoom() { 109 this.setState({rezoom: !this.state.rezoom}); 110 this.viewer.setRezoom(!this.state.rezoom); 134 this.setState({rezoom: !this.state.rezoom}, function() { 135 this.viewer.setRezoom(this.state.rezoom); 136 }); 111 137 } 112 138 … … 115 141 */ 116 142 switchAutorotate() { 117 this.setState({autorotate: !this.state.autorotate}); 118 this.viewer.setAutoRotate(!this.state.autorotate); 143 if (this.state.rezoom) { 144 this.switchRezoom(); 145 } 146 this.setState({autorotate: !this.state.autorotate}, function() { 147 console.log(this.state.autorotate); 148 this.viewer.setAutoRotate(this.state.autorotate); 149 }); 119 150 } 120 151 … … 127 158 mousePosition.x = ((evt.clientX - bound.left) / bound.width) * 2 - 1; 128 159 mousePosition.y = -((evt.clientY - bound.top) / bound.height) * 2 + 1; 129 //let vector = new THREE.Vector3(mousePosition.x, mousePosition.y, 0.5);130 160 let vector = new THREE.Vector2(mousePosition.x, mousePosition.y); 131 161 return vector; … … 137 167 */ 138 168 handleMouseDown(evt) { 169 if (this.state.rezoom) { 170 this.switchRezoom(); 171 } 172 173 if (this.state.autorotate) { 174 this.switchAutorotate(); 175 } 176 139 177 evt.preventDefault(); 140 178 let mousePosition = this.getMousePosition(evt); … … 147 185 */ 148 186 handleMouseUp(evt) { 187 188 let position1 = []; 189 let position2 = []; 190 let rotation1 = []; 191 let rotation2 = []; 192 this.viewer.framstick1.mesh.position.toArray(position1); 193 this.viewer.framstick2.mesh.position.toArray(position2); 194 this.viewer.framstick1.mesh.rotation.toArray(rotation1); 195 this.viewer.framstick2.mesh.rotation.toArray(rotation2); 196 197 this.props.handleChangePosition1(position1); 198 this.props.handleChangePosition2(position2); 199 this.props.handleChangeRotation1(rotation1); 200 this.props.handleChangeRotation2(rotation2); 201 149 202 evt.preventDefault(); 150 203 let mousePosition = this.getMousePosition(evt); … … 160 213 let mousePosition = this.getMousePosition(evt); 161 214 this.viewer.handleMouseMove(mousePosition); 162 } 163 164 215 } 165 216 166 217 render() { … … 170 221 <tr onMouseDown={ev => {if (ev) ev.stopPropagation();}}> 171 222 <td rowSpan={2} style={{position:'relative', verticalAlign: 'top', alignContent: 'left'}}> 172 <div style={{height: '100%', width: '100%', position: 'absolute', transform: 'translateZ(0)'}} onMouseDown={ev => {if (ev) ev.stopPropagation();}} onTouchStart={ev => {if (ev) ev.stopPropagation();}}>223 <div id="simcontainer" style={{height: '100%', width: '100%', position: 'absolute', transform: 'translateZ(0)'}} onMouseDown={ev => {if (ev) ev.stopPropagation();}} onTouchStart={ev => {if (ev) ev.stopPropagation();}}> 173 224 <canvas ref={(mount) => {this.mount = mount;}} onMouseDown={(evt) => this.handleMouseDown(evt)} onMouseUp={(evt) => this.handleMouseUp(evt)} onMouseMove={(evt) => this.handleMouseMove(evt)} style={{position: 'absolute', zIndex: 1}}></canvas> 174 225 <Md3dRotation onClick={() => this.switchAutorotate()} style={{zIndex: 2, position: 'absolute', left: '5%', bottom: 0, width: '20%', height: '20%', maxWidth: '40px', maxHeight: '40px', minWidth: '15px', minHeight: '15px', color: this.state.autorotate ? 'green' : 'black'}} />
Note: See TracChangeset
for help on using the changeset viewer.