Remove ThreeCanvas.kt
This commit is contained in:
parent
cb4d8af925
commit
5127e9ba78
@ -1,67 +0,0 @@
|
|||||||
package canvas
|
|
||||||
|
|
||||||
import kotlinx.browser.window
|
|
||||||
import org.w3c.dom.Element
|
|
||||||
import org.w3c.dom.HTMLCanvasElement
|
|
||||||
import space.kscience.visionforge.Colors
|
|
||||||
import three.WebGLRenderer
|
|
||||||
import three.cameras.PerspectiveCamera
|
|
||||||
import three.core.Object3D
|
|
||||||
import three.external.controls.OrbitControls
|
|
||||||
import three.scenes.Scene
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is analogous to the class from VisionForge with the same name.
|
|
||||||
* I keep it here in case imports are broken (they are broken at the time i write this).
|
|
||||||
*/
|
|
||||||
internal class ThreeCanvas(
|
|
||||||
val element: Element,
|
|
||||||
) {
|
|
||||||
private val scene = Scene()
|
|
||||||
private val camera = PerspectiveCamera(75, 4.0 / 3.0, 0.1, 1000)
|
|
||||||
private val renderer = WebGLRenderer { antialias = true }.apply {
|
|
||||||
setClearColor(Colors.darkgray, 1)
|
|
||||||
toneMapping = 4 // ACES filmic tone mapping
|
|
||||||
}
|
|
||||||
private val canvas = (renderer.domElement as HTMLCanvasElement).apply {
|
|
||||||
className += "three-canvas"
|
|
||||||
style.apply {
|
|
||||||
width = "100%"
|
|
||||||
height = "100%"
|
|
||||||
display = "block"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
element.appendChild(canvas)
|
|
||||||
camera.position.z = 5.0
|
|
||||||
OrbitControls(camera, element)
|
|
||||||
updateSize()
|
|
||||||
window.onresize = { updateSize() }
|
|
||||||
renderer.setAnimationLoop {
|
|
||||||
renderer.render(scene, camera)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun add(obj: Object3D) {
|
|
||||||
console.log("Adding objects...")
|
|
||||||
scene.add(obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun remove(obj: Object3D) {
|
|
||||||
console.log("Removing objects...")
|
|
||||||
scene.remove(obj)
|
|
||||||
val geometriesInMemotyCount = renderer.asDynamic()["info"]["memory"]["geometries"].toString()
|
|
||||||
console.log("Geometries: $geometriesInMemotyCount")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateSize() {
|
|
||||||
val width = element.clientWidth
|
|
||||||
val height = element.clientHeight
|
|
||||||
canvas.width = width
|
|
||||||
canvas.height = height
|
|
||||||
renderer.setSize(width, height, false)
|
|
||||||
camera.aspect = width.toDouble() / height.toDouble()
|
|
||||||
camera.updateProjectionMatrix()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user