Ignore:
Timestamp:
04/18/20 20:18:36 (4 years ago)
Author:
Maciej Komosinski
Message:

Added the actual functionality of the app in place of previous draft

File:
1 edited

Legend:

Unmodified
Added
Removed
  • js/human_3d_alignment/src/widgets/similviewer.jsx

    r881 r911  
    33import React from 'react';
    44import ReactDOM from 'react-dom';
     5import * as THREE from 'three';
    56import Sviewer from '../visualization/sviewer';
    67import { Md3dRotation, MdYoutubeSearchedFor } from 'react-icons/lib/md';
    7 import GenotypeParser from '../utils/genotypeparser';
    8 import _ from 'lodash';
    9 import * as THREE from 'three';
    108
    119/**
     
    2422            rezoom: true,
    2523            valid: true,
    26             clicked: false
     24            clicked: false,
     25            controlMode: 'translate',
     26            round: 0
    2727        };
    2828        this.start = this.start.bind(this);
     
    3838        let temp2 = ReactDOM.findDOMNode(this.mount).parentNode;
    3939        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);
    4640        this.viewer.setAutoRotate(this.state.autorotate);
    4741        this.viewer.setRezoom(this.state.rezoom);
    48         //this.elementspicker = new ElementsPicker(this.viewer.scene, this.viewer.camera.getPerspectiveCamera());
     42
    4943        this.renderScene = this.viewer.renderScene.bind(this.viewer);
    5044        this.lastw = temp2.clientWidth;
     
    9488            this.viewer.renderer,
    9589            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        }
    96121    }
    97122
     
    107132     */
    108133    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        });
    111137    }
    112138
     
    115141     */
    116142    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        });
    119150    }
    120151
     
    127158        mousePosition.x = ((evt.clientX - bound.left) / bound.width) * 2 - 1;
    128159        mousePosition.y = -((evt.clientY - bound.top) / bound.height) * 2 + 1;
    129         //let vector = new THREE.Vector3(mousePosition.x, mousePosition.y, 0.5);
    130160        let vector = new THREE.Vector2(mousePosition.x, mousePosition.y);
    131161        return vector;
     
    137167     */
    138168    handleMouseDown(evt) {
     169        if (this.state.rezoom) {
     170            this.switchRezoom();
     171        }
     172
     173        if (this.state.autorotate) {
     174            this.switchAutorotate();
     175        }
     176
    139177        evt.preventDefault();
    140178        let mousePosition = this.getMousePosition(evt);
     
    147185     */
    148186    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
    149202        evt.preventDefault();
    150203        let mousePosition = this.getMousePosition(evt);
     
    160213        let mousePosition = this.getMousePosition(evt);
    161214        this.viewer.handleMouseMove(mousePosition);
    162     }
    163 
    164    
     215    }   
    165216     
    166217    render() {
     
    170221                    <tr onMouseDown={ev => {if (ev) ev.stopPropagation();}}>
    171222                        <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();}}>
    173224                                <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>
    174225                                <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.