Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit f51e885

Browse files
committed
Started migration of threejs to typescript 🚀
1 parent 936bb0f commit f51e885

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed
Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,31 @@ import {
1717
RepeatWrapping,
1818
MeshStandardMaterial,
1919
PlaneGeometry
20-
} from 'three/build/three.module.js'
21-
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
22-
import { PLYLoader } from 'three/examples/jsm/loaders/PLYLoader.js'
20+
} from 'three'
21+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
22+
import { PLYLoader } from 'three/examples/jsm/loaders/PLYLoader'
2323
import { animation } from '../common/animation'
2424

25-
const sceneThreeJS = () => {
25+
const camera3D = (): PerspectiveCamera => {
26+
const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
27+
camera.position.z = 8
28+
camera.position.y = 0
29+
camera.position.x = 0
30+
return camera
31+
}
32+
33+
const renderer3D = (): WebGLRenderer => {
34+
const renderer = new WebGLRenderer({ alpha: true })
35+
renderer.physicallyCorrectLights = true
36+
// renderer.gammaInput = true
37+
// renderer.gammaOutput = true
38+
renderer.shadowMap.enabled = true
39+
renderer.shadowMap.type = PCFSoftShadowMap
40+
renderer.setSize(window.innerWidth, window.innerHeight)
41+
return renderer
42+
}
43+
44+
const sceneThreeJS = (): void => {
2645
const plyLoader = new PLYLoader()
2746
const scene = new Scene()
2847
const textureLoader = new TextureLoader()
@@ -119,41 +138,24 @@ const renderLoop = (renderer, scene, camera, orbit) => {
119138
renderFrame()
120139
}
121140

122-
const lights = (scene) => {
123-
scene.add(pointLight())
124-
scene.add(new HemisphereLight(0x303F9F, 0x000000, 1))
125-
}
126-
127-
const camera3D = () => {
128-
const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
129-
camera.position.z = 8
130-
camera.position.y = 0
131-
camera.position.x = 0
132-
return camera
133-
}
134-
135-
const pointLight = () => {
141+
const pointLight = (): PointLight => {
136142
const light = new PointLight(0xffffff, 1, 20, 2)
137143
light.power = 1700
138144
light.castShadow = true
139145
light.shadow.mapSize.width = 512
140-
light.shadow.mapSize.heigth = 512
146+
light.shadow.mapSize.height = 512
141147
light.shadow.radius = 1.5
142148
light.position.set(0, 5, 3)
143149
return light
144150
}
145151

146-
const renderer3D = () => {
147-
const renderer = new WebGLRenderer({ alpha: true })
148-
renderer.physicallyCorrectLights = true
149-
renderer.gammaInput = true
150-
renderer.gammaOutput = true
151-
renderer.shadowMap.enabled = true
152-
renderer.shadowMap.type = PCFSoftShadowMap
153-
renderer.setSize(window.innerWidth, window.innerHeight)
154-
return renderer
152+
const lights = (scene: Scene): void => {
153+
scene.add(pointLight())
154+
scene.add(new HemisphereLight(0x303F9F, 0x000000, 1))
155155
}
156156

157+
158+
157159
const stars = (textureLoader, completeLoad) => {
158160
textureLoader.load('assets/models/textures/circle.png', function (texture) {
159161
const starsGeometry = new Geometry()
@@ -208,7 +210,7 @@ const floor = (textureLoader, completionFunction) => {
208210
})
209211
}
210212

211-
const showRenderingSurfaceAnimation = () => animation('rendering-surface', 'show')
213+
const showRenderingSurfaceAnimation = (): void => animation('rendering-surface', 'show')
212214

213215
const setWindowResizeListener = (camera, renderer) => {
214216
window.addEventListener('resize', () => {

0 commit comments

Comments
 (0)