Workaround for csg uv bug
This commit is contained in:
parent
c82c0ecea3
commit
ba637413c7
@ -1,7 +1,6 @@
|
|||||||
import kotlinx.browser.document
|
import kotlinx.browser.document
|
||||||
import kotlinx.css.height
|
import kotlinx.css.height
|
||||||
import kotlinx.css.vh
|
import kotlinx.css.pct
|
||||||
import kotlinx.css.vw
|
|
||||||
import kotlinx.css.width
|
import kotlinx.css.width
|
||||||
import react.child
|
import react.child
|
||||||
import react.dom.render
|
import react.dom.render
|
||||||
@ -32,8 +31,8 @@ private class JsPlaygroundApp : Application {
|
|||||||
render(element) {
|
render(element) {
|
||||||
styledDiv {
|
styledDiv {
|
||||||
css{
|
css{
|
||||||
height = 100.vh
|
height = 100.pct
|
||||||
width = 100.vw
|
width = 100.pct
|
||||||
}
|
}
|
||||||
child(ThreeCanvasWithControls) {
|
child(ThreeCanvasWithControls) {
|
||||||
attrs {
|
attrs {
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>js-playground</title>
|
<title>js-playground</title>
|
||||||
<script src="js-playground.js"></script>
|
<script src="js-playground.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body class="application">
|
||||||
<div id="playground"></div>
|
<div id="playground"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -3,7 +3,6 @@ package space.kscience.visionforge.examples
|
|||||||
import space.kscience.dataforge.context.Context
|
import space.kscience.dataforge.context.Context
|
||||||
import space.kscience.gdml.GdmlShowCase
|
import space.kscience.gdml.GdmlShowCase
|
||||||
import space.kscience.visionforge.gdml.toVision
|
import space.kscience.visionforge.gdml.toVision
|
||||||
import space.kscience.visionforge.html.ResourceLocation
|
|
||||||
import space.kscience.visionforge.solid.Solids
|
import space.kscience.visionforge.solid.Solids
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
@ -11,7 +10,7 @@ fun main() {
|
|||||||
plugin(Solids)
|
plugin(Solids)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.makeVisionFile(resourceLocation = ResourceLocation.EMBED) {
|
context.makeVisionFile {
|
||||||
vision("canvas") { GdmlShowCase.babyIaxo().toVision() }
|
vision("canvas") { GdmlShowCase.babyIaxo().toVision() }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
@file:JsModule("three")
|
@file:JsModule("three")
|
||||||
@file:JsNonModule
|
@file:JsNonModule
|
||||||
|
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "unused")
|
||||||
|
|
||||||
package info.laht.threekt
|
package info.laht.threekt
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ import space.kscience.visionforge.solid.minus
|
|||||||
|
|
||||||
internal fun Point3D.toVector() = Vector3(x, y, z)
|
internal fun Point3D.toVector() = Vector3(x, y, z)
|
||||||
|
|
||||||
internal fun <T> MutableList<T>.add(f1: T, f2: T, f3: T) {
|
internal fun <T> MutableList<T>.add(vararg values: T) {
|
||||||
add(f1)
|
values.forEach {
|
||||||
add(f2)
|
add(it)
|
||||||
add(f3)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,16 +25,16 @@ public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
|||||||
private val indices = ArrayList<Short>()
|
private val indices = ArrayList<Short>()
|
||||||
private val positions = ArrayList<Float>()
|
private val positions = ArrayList<Float>()
|
||||||
private val normals = ArrayList<Float>()
|
private val normals = ArrayList<Float>()
|
||||||
private val colors = ArrayList<Float>()
|
// private val colors = ArrayList<Float>()
|
||||||
|
|
||||||
private val vertexCache = HashMap<Point3D, Short>()
|
private val vertexCache = HashMap<Point3D, Short>()
|
||||||
private var counter: Short = -1
|
private var counter: Short = -1
|
||||||
|
|
||||||
private fun indexOf(vertex: Point3D, normal: Point3D): Short = vertexCache.getOrPut(vertex) {
|
private fun vertex(vertex: Point3D, normal: Point3D): Short = vertexCache.getOrPut(vertex) {
|
||||||
//add vertex and update cache if needed
|
//add vertex and update cache if needed
|
||||||
positions.add(vertex.x, vertex.y, vertex.z)
|
positions.add(vertex.x, vertex.y, vertex.z)
|
||||||
normals.add(normal.x, vertex.y, vertex.z)
|
normals.add(normal.x, vertex.y, vertex.z)
|
||||||
colors.add(1f, 1f, 1f)
|
//colors.add(1f, 1f, 1f)
|
||||||
counter++
|
counter++
|
||||||
counter
|
counter
|
||||||
}
|
}
|
||||||
@ -42,19 +42,21 @@ public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
|||||||
override fun face(vertex1: Point3D, vertex2: Point3D, vertex3: Point3D, normal: Point3D?, meta: Meta) {
|
override fun face(vertex1: Point3D, vertex2: Point3D, vertex3: Point3D, normal: Point3D?, meta: Meta) {
|
||||||
val actualNormal: Point3D = normal ?: (vertex3 - vertex2) cross (vertex1 - vertex2)
|
val actualNormal: Point3D = normal ?: (vertex3 - vertex2) cross (vertex1 - vertex2)
|
||||||
indices.add(
|
indices.add(
|
||||||
indexOf(vertex1, actualNormal),
|
vertex(vertex1, actualNormal),
|
||||||
indexOf(vertex2, actualNormal),
|
vertex(vertex2, actualNormal),
|
||||||
indexOf(vertex3, actualNormal)
|
vertex(vertex3, actualNormal)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun build(): BufferGeometry = BufferGeometry().apply {
|
override fun build(): BufferGeometry = BufferGeometry().apply {
|
||||||
//setIndex(Int16BufferAttribute(indices.toShortArray(), 1))
|
|
||||||
setIndex(indices.toTypedArray())
|
setIndex(indices.toTypedArray())
|
||||||
setAttribute("position", Float32BufferAttribute(positions.toTypedArray(), 3))
|
setAttribute("position", Float32BufferAttribute(positions.toTypedArray(), 3))
|
||||||
setAttribute("normal", Float32BufferAttribute(normals.toTypedArray(), 3))
|
setAttribute("normal", Float32BufferAttribute(normals.toTypedArray(), 3))
|
||||||
//setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3))
|
//setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3))
|
||||||
|
//a temporary fix for CSG problem
|
||||||
|
val uvsArray = Array<Float>((counter+1)*2){0f}
|
||||||
|
setAttribute("uv", Float32BufferAttribute(uvsArray, 2))
|
||||||
|
|
||||||
computeBoundingSphere()
|
computeBoundingSphere()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user