1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import * as THREE from 'three' import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
const $app = document.getElementById('app')
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 1000 ) camera.position.set(0, 0, 60)
const renderer = new THREE.WebGLRenderer({ antialias: true, }) renderer.setSize(window.innerWidth, window.innerHeight) $app.appendChild(renderer.domElement)
const emptyGeometry = new THREE.BufferGeometry()
const vertices = new Float32Array([ 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 10, 0 ])
const positionAttr = new THREE.BufferAttribute(vertices, 3)
emptyGeometry.attributes.position = positionAttr
const pointMtr = new THREE.PointsMaterial()
const pointsObj = new THREE.Points(emptyGeometry, pointMtr) scene.add(pointsObj)
const lineMaterial = new THREE.LineBasicMaterial()
const lineObj = new THREE.LineSegments(emptyGeometry, lineMaterial) lineObj.position.set(-2, -2, 0)
const meshMaterial = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide })
const meshObj = new THREE.Mesh(emptyGeometry, meshMaterial) meshObj.position.set(2, 2, 0)
scene.add(lineObj, meshObj)
new OrbitControls(camera, renderer.domElement)
function animate() { requestAnimationFrame(animate) renderer.render(scene, camera) } animate()
|