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
| import * as THREE from 'three' import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 100 ) camera.position.z = 30
const renderer = new THREE.WebGLRenderer() renderer.setSize(window.innerWidth, window.innerHeight) app.appendChild(renderer.domElement)
const R = 2 const H = 5
const line1 = new THREE.LineCurve( new THREE.Vector2(R, H), new THREE.Vector2(R, 0) )
const arc = new THREE.ArcCurve(0, 0, R, 0, Math.PI, true)
const line2 = new THREE.LineCurve( new THREE.Vector2(-R, 0), new THREE.Vector2(-R, H) )
const curvePath = new THREE.CurvePath()
curvePath.curves.push(line1, arc, line2)
const geo = new THREE.BufferGeometry() geo.setFromPoints(curvePath.getSpacedPoints(10)) const mat = new THREE.LineBasicMaterial() const line = new THREE.Line(geo, mat) scene.add(line)
const controls = new OrbitControls(camera, app)
renderer.setAnimationLoop(() => { renderer.render(scene, camera) })
|