Files
2024-03-27 13:08:46 +01:00

65 lines
3.0 KiB
JavaScript

import * as THREE1 from "../Libs/node_modules/three/build/three.module.js";
export function getStaticRef( thick, length) {
// color definition
const RED = 0xd9534f ;
const DARK_RED = 0xAE423F ;
const GREEN = 0x5cb85c ;
const DARK_GREEN = 0x4A934A ;
const BLUE = 0x0275d8 ;
const DARK_BLUE = 0x025EAD ;
const BLACK = 0x000000 ;
// cylinder geometry
const axis_geometry = new THREE1.CylinderGeometry( thick, thick, length, 32) ;
const arrow_geometry = new THREE1.CylinderGeometry( 0., 2 * thick, length / 5, 32) ;
// materials
const x_material = new THREE1.MeshBasicMaterial({ color: RED}) ;
const x_darkMaterial = new THREE1.MeshBasicMaterial({ color : DARK_RED}) ;
const y_material = new THREE1.MeshBasicMaterial({ color: GREEN}) ;
const y_darkMaterial = new THREE1.MeshBasicMaterial({ color: DARK_GREEN}) ;
const z_material = new THREE1.MeshBasicMaterial({ color: BLUE}) ;
const z_darkMaterial = new THREE1.MeshBasicMaterial({ color : DARK_BLUE}) ;
// line-meshes
const x_cylinder = new THREE1.Mesh( axis_geometry, x_material) ;
const y_cylinder = new THREE1.Mesh( axis_geometry, y_material) ;
const z_cylinder = new THREE1.Mesh( axis_geometry, z_material) ;
// arrow-meshes
const x_cylinder_arrow = new THREE1.Mesh( arrow_geometry, x_darkMaterial) ;
const y_cylinder_arrow = new THREE1.Mesh( arrow_geometry, y_darkMaterial) ;
const z_cylinder_arrow = new THREE1.Mesh( arrow_geometry, z_darkMaterial) ;
// rotation for axis and arrows
x_cylinder.rotateOnAxis( new THREE1.Vector3( 0., 0., 1.), - Math.PI / 2) ;
y_cylinder.rotateOnAxis( new THREE1.Vector3( 1., 0., 0.), Math.PI / 2) ;
x_cylinder_arrow.rotateOnAxis( new THREE1.Vector3( 0., 0., 1.), - Math.PI / 2) ;
y_cylinder_arrow.rotateOnAxis( new THREE1.Vector3( 1., 0., 0.), Math.PI / 2) ;
// translations
x_cylinder.translateY( length / 2) ;
y_cylinder.translateY( length / 2) ;
z_cylinder.translateY( length / 2) ;
x_cylinder_arrow.translateY( 1.1 * length) ;
y_cylinder_arrow.translateY( 1.1 * length) ;
z_cylinder_arrow.translateY( 1.1 * length) ;
// origin
const sphere_geometry = new THREE1.SphereGeometry( 1.5 * thick, 32, 32) ;
const sphere_material = new THREE1.MeshBasicMaterial( { color: BLACK}) ;
const sphere_origin = new THREE1.Mesh( sphere_geometry, sphere_material ) ;
// creating the group
const axisGroup = new THREE1.Group() ;
axisGroup.add( x_cylinder) ;
axisGroup.add( y_cylinder) ;
axisGroup.add( z_cylinder) ;
axisGroup.add( x_cylinder_arrow) ;
axisGroup.add( y_cylinder_arrow) ;
axisGroup.add( z_cylinder_arrow) ;
axisGroup.add( sphere_origin) ;
return axisGroup ;
}
export function updateRef( ref, myCamera, controls) {
var invRotMat = new THREE1.Matrix4() ;
invRotMat.extractRotation( controls.object.matrix) ;
invRotMat.invert() ;
var euler = new THREE1.Euler().setFromRotationMatrix( invRotMat) ;
ref.rotation.set( euler.x, euler.y , euler.z) ;
myCamera.updateMatrix() ;
}