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