Changeset 911 for js/human_3d_alignment/src/visualization
- Timestamp:
- 04/18/20 20:18:36 (5 years ago)
- Location:
- js/human_3d_alignment/src/visualization
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
js/human_3d_alignment/src/visualization/camera.js
r881 r911 87 87 let modelSphere = modelBox.getBoundingSphere(); 88 88 89 this.targetPosition = modelSphere.center.clone(); 90 this.cameraPosition = modelSphere.center.clone().addScalar(modelSphere.radius); 91 89 92 return { 90 93 target: { -
js/human_3d_alignment/src/visualization/jointmeshfactory.js
r881 r911 33 33 * @returns {Mesh} Mesh for a given joint 34 34 */ 35 getNewJointMesh(joint, shapeConfig) {35 getNewJointMesh(joint, color, shapeConfig) { 36 36 let firstPartPosVec = new THREE.Vector3( 37 37 joint.get_part1().get_p().get_x(), … … 42 42 joint.get_part2().get_p().get_y(), 43 43 joint.get_part2().get_p().get_z()); 44 //let line = new THREE.LineCurve3(firstPartPosVec, secondPartPosVec);45 //let geometry = new THREE.TubeGeometry(line, numsegmentstube, shapeConfig.radius,46 // shapeConfig.radiusSegments, false);47 44 48 45 let direction = new THREE.Vector3().subVectors(secondPartPosVec, firstPartPosVec); 49 let orientation = new THREE.Matrix4(); 50 51 let geometry = new THREE.CylinderGeometry(shapeConfig.radius, shapeConfig.radius, direction.length(), shapeConfig.radiusSegments); 52 53 54 let material = this.transformations.getNewMaterial( 55 joint.get_vcolor().get_x(), 56 joint.get_vcolor().get_y(), 57 joint.get_vcolor().get_z()); 58 material.transparent = shapeConfig.isTransparent; 59 material.opacity = shapeConfig.opacity; 60 //let mesh = new THREE.Mesh(geometry, material); 61 46 let geometry = new THREE.CylinderGeometry(shapeConfig.radius, shapeConfig.radius, direction.length() - 2 * 0.18, shapeConfig.radiusSegments); 47 let material = this.transformations.getNewMaterial(color); 62 48 let mesh = new THREE.Mesh( geometry, material ); //new Physijs.CylinderMesh( geometry, Physijs.createMaterial(material) ); //new THREE.Mesh( geometry, material ); 63 49 50 let orientation = new THREE.Matrix4(); 64 51 orientation.lookAt(firstPartPosVec, secondPartPosVec, new THREE.Object3D().up); 65 52 orientation.multiply(new THREE.Matrix4().set( … … 82 69 mesh: mesh, 83 70 connectedParts: [], 84 showTransparent: shapeConfig.isTransparent71 showTransparent: true 85 72 }; 86 73 return mesh; … … 115 102 * @returns {JointMesh} new joint mesh, for properties of Object look at addConnectionInfo jointMesh param documentation 116 103 */ 117 create(joint, partMeshes) {104 create(joint, color, partMeshes) { 118 105 let result; 119 106 let shape = joint.get_shape(); 120 107 121 108 if (this.jointShapes['SHAPE_FIXED'].value == shape) { 122 result = this.getNewJointMesh(joint, this.config.linkShape);109 result = this.getNewJointMesh(joint, color, this.config.linkShape); 123 110 } else { 124 result = this.getNewJointMesh(joint, this.config.cylinderShape);111 result = this.getNewJointMesh(joint, color, this.config.cylinderShape); 125 112 } 126 113 -
js/human_3d_alignment/src/visualization/partmeshfactory.js
r881 r911 36 36 * @returns {PartMesh} info about part mesh 37 37 */ 38 getNewSphereMesh(part, sphereRadius, segments, applyScale) {38 getNewSphereMesh(part, color, sphereRadius, segments, applyScale) { 39 39 let geometry = new THREE.SphereGeometry(sphereRadius, segments, segments); 40 let material = this.transformations.getNewMaterial( 41 part.get_vcolor().get_x(), 42 part.get_vcolor().get_y(), 43 part.get_vcolor().get_z()); 40 let material = this.transformations.getNewMaterial(color); 44 41 let mesh = null; 45 42 if (applyScale) { … … 94 91 * @returns {PartMesh} info about part mesh 95 92 */ 96 getNewBoxMesh(part ) {93 getNewBoxMesh(part, color) { 97 94 let geometry = new THREE.BoxGeometry(2, 2, 2); 98 95 geometry.scale( … … 101 98 part.get_scale().get_z()); 102 99 103 let material = this.transformations.getNewMaterial( 104 part.get_vcolor().get_x(), 105 part.get_vcolor().get_y(), 106 part.get_vcolor().get_z()); 100 let material = this.transformations.getNewMaterial(color); 107 101 let mesh = new THREE.Mesh(geometry, material); 108 102 mesh.position.set( … … 133 127 * @returns {PartMesh} info about part mesh 134 128 */ 135 getNewCylinderMesh(part ) {129 getNewCylinderMesh(part, color) { 136 130 let geometry = new THREE.CylinderGeometry(1, 1, 2, 32); 137 let material = this.transformations.getNewMaterial( 138 part.get_vcolor().get_x(), 139 part.get_vcolor().get_y(), 140 part.get_vcolor().get_z()); 131 let material = this.transformations.getNewMaterial(color); 141 132 142 133 geometry.scale( … … 181 172 * @returns {PartMesh} info about part mesh 182 173 */ 183 create(part ) {174 create(part, color) { 184 175 185 176 let shape = part.get_shape(); … … 187 178 return this.getNewSphereMesh( 188 179 part, 180 color, 189 181 this.config.ellipsoidShape.radius, 190 182 this.config.ellipsoidShape.segments, true); 191 183 } 192 184 else if (this.partShapes['SHAPE_CUBOID'].value == shape) { 193 return this.getNewBoxMesh(part );185 return this.getNewBoxMesh(part, color); 194 186 } 195 187 else if (this.partShapes['SHAPE_CYLINDER'].value == shape) { 196 return this.getNewCylinderMesh(part );188 return this.getNewCylinderMesh(part, color); 197 189 } 198 190 return this.getNewSphereMesh( 199 191 part, 192 color, 200 193 this.config.defaultShape.radius, 201 194 this.config.defaultShape.segments, -
js/human_3d_alignment/src/visualization/sviewer.js
r881 r911 3 3 4 4 import * as THREE from 'three'; 5 import TrackballControls from 'three-trackballcontrols'; 6 import PartMeshFactory from './partmeshfactory'; 7 import JointMeshFactory from './jointmeshfactory'; 5 import Framstick from './framstick'; 8 6 import Scene from './scene'; 9 7 import Camera from './camera'; 10 import { geometry } from './transformations';8 const TransformControls = require('three-transform-controls')(THREE); 11 9 12 10 /** Camera class configuration for Viewer */ … … 66 64 */ 67 65 constructor(width, height, canvasdom) { 66 this.container = document.getElementById("simcontainer"); 67 68 this.meshes = []; 68 69 this.parts = []; 69 this.joints = []; 70 this.meshes = []; 71 this.parts2 = []; 72 this.joints2 = []; 73 this.meshes2 = []; 74 this.creature1 = new THREE.Group(); 75 this.creature2 = new THREE.Group(); 76 this.partfactory = new PartMeshFactory(geometry.part); 77 this.jointfactory = new JointMeshFactory(geometry.joint); 70 this.lines = []; 71 this.framstick1 = null; 72 this.framstick2 = null; 73 this.selected1 = []; 74 this.selected2 = []; 75 78 76 this.renderer = new THREE.WebGLRenderer({ 79 77 antialias: true, … … 85 83 this.scene = new Scene(); 86 84 this.camera = new Camera(cameraconfig, this.renderer.domElement, false); 87 //console.log(this.camera); 85 this.control = new TransformControls(this.camera.getPerspectiveCamera(), this.renderer.domElement); 86 this.control.addEventListener( 'change', (e) => { 87 this.addLines(this.selected1, this.selected2); 88 this.addText(); 89 }); 90 this.control.addEventListener( 'dragging-changed', function(e) { 91 this.camera.getCameraControl().enable = ! e.value; 92 }); 93 this.scene.add(this.control); 94 this.control.setMode( "translate" ); 95 88 96 let ambientLight = new THREE.AmbientLight(lightconfig.ambient.color); 89 97 this.scene.add(ambientLight); … … 100 108 bottomDirectionalLight.position.set(0, 0, lightconfig.directional.bottom.positionZ); 101 109 this.scene.add(bottomDirectionalLight); 110 102 111 this.renderer.setClearColor('gray'); 103 this.rezoom = true; 112 this.rezoom = false; 113 this.autorotate = false; 104 114 this.renderScene = this.renderScene.bind(this); 105 115 this.selectedelements = []; 106 116 107 117 this.mouse = new THREE.Vector2(); 108 this.offset = new THREE.Vector3();109 this.INTERSECTED = null;110 118 this.SELECTED = null; 111 112 this.plane = new THREE.Mesh( new THREE.PlaneGeometry(500, 500, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0x000000, opacity: 0.25, transparent: true, wireframe: true } ) ); 113 this.plane.visible = true; 114 this.scene.add( this.plane ); 115 116 this.controls = new TrackballControls( this.camera.getPerspectiveCamera() ); 117 this.projector = new THREE.Projector(); 118 this.controls.target = new THREE.Vector3(0, 0, 0); 119 this.controls.maxDistance = 150; 120 this.controls2 = null; 121 } 122 123 addMesh(meshes, parts, joints, model, creature) 124 { 125 let partsforjoints = []; 126 meshes = []; 127 parts = []; 128 joints = []; 129 for (let i = 0; i < model.getPartCount(); i++) { 130 let mesh = this.partfactory.create(model.getPart(i)); 131 partsforjoints.push(mesh.userData); 132 meshes.push(mesh); 133 parts.push(mesh); 134 creature.add(mesh); 135 } 136 137 for (let i = 0; i < model.getJointCount(); i++) { 138 let mesh = this.jointfactory.create(model.getJoint(i), partsforjoints); 139 meshes.push(mesh); 140 joints.push(mesh); 141 creature.add(mesh); 142 } 119 this.CLICKED = false; 120 121 122 this.lineMaterial = new THREE.LineBasicMaterial({ 123 color: 0xffff00, 124 transparent: true, 125 opacity: 0.5 126 }); 127 128 this.textLabels = []; 129 this.container = document.getElementById("simcontainer"); 130 } 131 132 /** 133 * Allow to clear view and add new pair of genotypes 134 * @param {string} genotype1 Genotype of first framstick 135 * @param {string} genotype2 Genotype of second framstick 136 */ 137 add2Genotypes(genotype1, genotype2) { 138 this.clearView(); 139 140 this.framstick1 = new Framstick(genotype1, this); 141 this.framstick2 = new Framstick(genotype2, this); 142 143 this.meshes = []; 144 this.parts = []; 145 146 for (let i = 0; i < this.framstick1.mesh.children.length; i++) { 147 this.meshes.push(this.framstick1.mesh.children[i]); 148 } 149 150 for (let i = 0; i < this.framstick2.mesh.children.length; i++) { 151 this.meshes.push(this.framstick2.mesh.children[i]); 152 } 153 154 for (let i = 0; i < this.framstick1.parts.length; i++) { 155 this.parts.push(this.framstick1.parts[i]); 156 } 157 158 for (let i = 0; i < this.framstick2.parts.length; i++) { 159 this.parts.push(this.framstick2.parts[i]); 160 } 161 162 this.framstick1.mesh.position.set( 0, -2, 0 ); 163 this.framstick2.mesh.position.set( 0, 2, 0 ); 164 165 this.framstick1.setPositions(); 166 this.framstick2.setPositions(); 167 168 this.framstick1.setColor('red'); 169 this.framstick2.setColor('blue'); 170 171 this.camera.zoomAll(this.meshes); 172 this.addText(); 173 } 174 175 /** 176 * Draw lines between selected parts of both framsticks 177 * @param {Array} selected1 array of values that user selected in fitview for first genotype 178 * @param {Array} selected2 array of values that user selected in fitview for second genotype 179 */ 180 addLines(selected1, selected2) { 181 for (let i = 0; i < this.lines.length; i++) { 182 this.scene.remove(this.lines[i]); 183 } 184 185 this.lines = []; 186 187 let pairs = (selected1.length + selected2.length) / 2; 188 189 for (let i = 0; i < pairs; i++) { 190 if (selected1[i] != ' ' && selected2[i] != ' ') { 191 let index1 = parseInt(selected1[i]) - 1; 192 let index2 = selected2[i].charCodeAt(0) - 65; 193 194 let tempV1 = new THREE.Vector3().copy(this.framstick1.positions[index1]).applyEuler(this.framstick1.mesh.rotation).add(this.framstick1.mesh.position); 195 let tempV2 = new THREE.Vector3().copy(this.framstick2.positions[index2]).applyEuler(this.framstick2.mesh.rotation).add(this.framstick2.mesh.position); 196 197 let geometry = new THREE.Geometry(); 198 geometry.vertices.push( tempV1 ); 199 geometry.vertices.push( tempV2 ); 200 201 let line = new THREE.Line( geometry, this.lineMaterial ); 202 this.lines.push(line); 203 } 204 } 205 206 for (let i = 0; i < this.lines.length; i++) { 207 this.scene.add(this.lines[i]); 208 } 209 } 210 211 addText() { 212 213 while (this.container.children.length > 3){ 214 this.container.removeChild(this.container.lastChild) 215 } 216 217 this.textLabels = []; 218 219 if (this.framstick1 != null && this.framstick2 != null) { 220 this.framstick1.addText(1); 221 this.framstick2.addText(2); 222 } 223 224 } 225 226 /** 227 * Allow to change mode of TransformControls 228 * @param {string} mode Selected mode of transformcontrols 229 */ 230 setMode(mode) { 231 this.control.setMode(mode); 143 232 } 144 233 … … 150 239 */ 151 240 handleMouseDown(position) { 152 this.raycaster.setFromCamera( position, this.camera.getPerspectiveCamera() ); 153 let intersectsC1 = this.raycaster.intersectObjects( this.creature1.children ); 154 let intersectsC2 = this.raycaster.intersectObjects( this.creature2.children ); 155 156 if ( intersectsC1.length > 0 || intersectsC2.length > 0 ) { 157 158 this.controls.enabled = false; 159 let obj = intersectsC1.length > 0 ? this.creature1 : this.creature2; 160 this.SELECTED = obj; 161 let intersects = this.raycaster.intersectObject( this.plane ); 162 this.offset.copy( intersects[ 0 ].point ).sub( this.plane.position ); 163 } 241 this.raycaster.setFromCamera( position, this.camera.getPerspectiveCamera() ); 242 let intersectsC1 = this.raycaster.intersectObjects( this.framstick1.mesh.children ); 243 let intersectsC2 = this.raycaster.intersectObjects( this.framstick2.mesh.children ); 244 245 if ( intersectsC1.length > 0 || intersectsC2.length > 0 ) { 246 247 let obj = intersectsC1.length > 0 ? this.framstick1 : this.framstick2; 248 249 if ( this.SELECTED ) { 250 if (this.SELECTED == obj) { 251 if (this.SELECTED == this.framstick1) { 252 obj.setColor('red'); 253 } else { 254 obj.setColor('blue'); 255 } 256 this.control.detach(); 257 this.SELECTED = null; 258 } else { 259 if (this.SELECTED == this.framstick1) { 260 this.SELECTED.setColor('red'); 261 } else { 262 this.SELECTED.setColor('blue'); 263 } 264 this.control.detach(); 265 obj.setColor('white'); 266 this.SELECTED = obj; 267 this.control.attach( obj.mesh ); 268 } 269 } else { 270 this.control.detach(); 271 obj.setColor('white'); 272 this.SELECTED = obj; 273 this.control.attach( obj.mesh ); 274 } 275 } else { 276 if (this.SELECTED) { 277 if (this.SELECTED == this.framstick1) { 278 this.SELECTED.setColor('red'); 279 } else { 280 this.SELECTED.setColor('blue'); 281 } 282 this.control.detach(); 283 this.SELECTED = null; 284 } 285 } 164 286 } 165 287 166 288 handleMouseUp() { 167 this.controls.enabled = true;168 this.SELECTED = null;169 170 if (this.INTERSECTED)171 {172 this.plane.position.copy(this.INTERSECTED.position);173 this.SELECTED = null;174 }175 289 } 176 290 177 291 handleMouseMove(position) { 178 this.raycaster.setFromCamera( position, this.camera.getPerspectiveCamera() );179 if ( this.SELECTED ) {180 let intersects = this.raycaster.intersectObject( this.plane );181 if (intersects[ 0 ])182 {this.SELECTED.position.copy( intersects[ 0 ].point.sub( this.offset ) );}183 return;184 }185 186 let intersectsC1 = this.raycaster.intersectObjects(this.creature1.children);187 let intersectsC2 = this.raycaster.intersectObjects(this.creature2.children);188 if (intersectsC1.length > 0 || intersectsC2.length > 0)189 {190 let obj = intersectsC1.length > 0 ? this.creature1 : this.creature2;191 this.INTERSECTED = obj;192 this.plane.position.copy( obj.position );193 this.plane.lookAt( this.camera.getPerspectiveCamera().position );194 }195 else196 {197 this.INTERSECTED = null;198 }199 200 }201 202 /**203 * Method uses ready Model to create and add meshes to the scene. If model is204 * undefined, an empty scene will be rendered.205 * @param {Module.Model} model input model 1206 * @param {Module.Model} model input model 2207 */208 loadMeshesFromModel(model, model2) {209 this.clearView();210 if (typeof model !== 'undefined') {211 212 this.addMesh(this.meshes, this.parts, this.joints, model, this.creature1);213 this.addMesh(this.meshes2, this.parts2, this.joints2, model2, this.creature2);214 this.creature2.position.set( 0, 0, 0 );215 this.creature2.position.set( 0, -1, 0 );216 this.scene.add(this.creature1);217 this.scene.add(this.creature2);218 if (this.rezoom) {219 this.camera.zoomAll(this.meshes);220 }221 }222 292 } 223 293 … … 251 321 this.camera.getPerspectiveCamera().updateProjectionMatrix(); 252 322 this.renderer.setSize(width, height); 253 //console.log(this.renderer.getSize());254 323 this.renderer.setPixelRatio(window.devicePixelRatio || 1); 255 324 } … … 262 331 setRezoom(rezoom) { 263 332 this.rezoom = rezoom; 264 this.camera.zoomAll(this.meshes); 333 if (this.rezoom) { 334 this.camera.zoomAll(this.meshes); 335 } 265 336 } 266 337 … … 277 348 */ 278 349 clearView() { 279 this.scene.clear(); 350 if (this.framstick1 != null && this.framstick2 != null) { 351 this.scene.remove(this.framstick1.mesh); 352 this.scene.remove(this.framstick2.mesh); 353 } 354 this.control.detach(); 355 while (this.container.children.length > 3) { 356 this.container.removeChild(this.container.lastChild) 357 } 358 359 this.SELECTED = null; 280 360 } 281 361 -
js/human_3d_alignment/src/visualization/transformations.js
r881 r911 45 45 cylinderShape: { 46 46 radius: 0.1, 47 radiusSegments: 10, 48 isTransparent: false, 49 opacity: 1 47 radiusSegments: 10 50 48 }, 51 49 linkShape: { 52 50 radius: 0.04, 53 radiusSegments: 10, 54 isTransparent: true, 55 opacity: 0.2 51 radiusSegments: 10 56 52 } 57 53 } … … 186 182 * @returns {MeshPhongMaterial} new material for Mesh 187 183 */ 188 getNewMaterial(r, g, b) { 189 let color = new THREE.Color( 190 this.calcColorComponent(r), 191 this.calcColorComponent(g), 192 this.calcColorComponent(b)); 193 return new THREE.MeshPhongMaterial({ color: color }); 184 getNewMaterial(color) { 185 return new THREE.MeshPhongMaterial({ 186 color: color, 187 transparent: true, 188 opacity: 0.6, 189 reflectivity: 0.2, 190 shininess: 600 191 }); 194 192 } 195 193
Note: See TracChangeset
for help on using the changeset viewer.