v0.2.0-dev-22 #47

Merged
altavir merged 158 commits from dev into master 2021-07-17 11:04:22 +03:00
6 changed files with 53 additions and 25 deletions
Showing only changes of commit c82c0ecea3 - Show all commits

View File

@ -223,7 +223,7 @@ abstract external class BufferAttribute protected constructor(
external class Float32BufferAttribute( external class Float32BufferAttribute(
array: FloatArray, array: Array<Float>,
itemSize: Int, itemSize: Int,
normalized: Boolean = definedExternally normalized: Boolean = definedExternally
) : BufferAttribute ) : BufferAttribute

View File

@ -36,7 +36,7 @@ import info.laht.threekt.materials.Material
open external class Mesh(geometry: BufferGeometry?, material: Material?) : Object3D { open external class Mesh(geometry: BufferGeometry?, material: Material?) : Object3D {
var geometry: dynamic var geometry: BufferGeometry
var material: Material var material: Material
var drawMode: Int var drawMode: Int

View File

@ -36,7 +36,8 @@ public abstract class MeshThreeFactory<in T : Solid>(
matrixAutoUpdate = false matrixAutoUpdate = false
//set position for mesh //set position for mesh
updatePosition(obj) updatePosition(obj)
}.applyProperties(obj) applyProperties(obj)
}
//add listener to object properties //add listener to object properties
obj.onPropertyChange(three.updateScope) { name -> obj.onPropertyChange(three.updateScope) { name ->

View File

@ -1,30 +1,60 @@
package space.kscience.visionforge.solid.three package space.kscience.visionforge.solid.three
import CSG import CSG
import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Object3D
import info.laht.threekt.math.Matrix4
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import space.kscience.dataforge.names.startsWith
import space.kscience.visionforge.onPropertyChange
import space.kscience.visionforge.solid.Composite import space.kscience.visionforge.solid.Composite
import space.kscience.visionforge.solid.CompositeType import space.kscience.visionforge.solid.CompositeType
import kotlin.reflect.KClass
/** /**
* This should be inner, because it uses object builder * This should be inner, because it uses object builder
*/ */
public class ThreeCompositeFactory(public val three: ThreePlugin) : MeshThreeFactory<Composite>(Composite::class) { public class ThreeCompositeFactory(public val three: ThreePlugin) : ThreeFactory<Composite> {
override fun buildGeometry(obj: Composite): BufferGeometry { // override fun buildGeometry(obj: Composite): BufferGeometry {
// val first = three.buildObject3D(obj.first) as? Mesh ?: error("First part of composite is not a mesh")
// //first.updateMatrix()
// val second = three.buildObject3D(obj.second) as? Mesh ?: error("Second part of composite is not a mesh")
// //second.updateMatrix()
// val firstCSG = CSG.fromMesh(first)
// val secondCSG = CSG.fromMesh(second)
//// val resultCSG = when (obj.compositeType) {
//// CompositeType.UNION -> firstCSG.union(secondCSG)
//// CompositeType.INTERSECT -> firstCSG.intersect(secondCSG)
//// CompositeType.SUBTRACT -> firstCSG.subtract(secondCSG)
//// }
//// return resultCSG.toGeometry(second.matrix)
//
// val resultMesh: Mesh = when (obj.compositeType) {
// CompositeType.UNION -> CSG.union(first,second)
// CompositeType.INTERSECT -> CSG.intersect(first,second)
// CompositeType.SUBTRACT -> CSG.subtract(first,second)
// }
// return resultMesh.geometry
// }
override val type: KClass<in Composite> get() = Composite::class
override fun invoke(three: ThreePlugin, obj: Composite): Object3D {
val first = three.buildObject3D(obj.first) as? Mesh ?: error("First part of composite is not a mesh") val first = three.buildObject3D(obj.first) as? Mesh ?: error("First part of composite is not a mesh")
first.updateMatrix()
val second = three.buildObject3D(obj.second) as? Mesh ?: error("Second part of composite is not a mesh") val second = three.buildObject3D(obj.second) as? Mesh ?: error("Second part of composite is not a mesh")
second.updateMatrix() return when (obj.compositeType) {
val firstCSG = CSG.fromMesh(first) CompositeType.UNION -> CSG.union(first,second)
val secondCSG = CSG.fromMesh(second) CompositeType.INTERSECT -> CSG.intersect(first,second)
val resultCSG = when (obj.compositeType) { CompositeType.SUBTRACT -> CSG.subtract(first,second)
CompositeType.UNION -> firstCSG.union(secondCSG) }.apply {
CompositeType.INTERSECT -> firstCSG.intersect(secondCSG) updatePosition(obj)
CompositeType.SUBTRACT -> firstCSG.subtract(secondCSG) applyProperties(obj)
obj.onPropertyChange(three.updateScope) { name ->
when {
//name.startsWith(WIREFRAME_KEY) -> mesh.applyWireFrame(obj)
name.startsWith(MeshThreeFactory.EDGES_KEY) -> applyEdges(obj)
else -> updateProperty(obj, name)
}
}
} }
return resultCSG.toGeometry(Matrix4())
} }
} }

View File

@ -52,8 +52,8 @@ public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
override fun build(): BufferGeometry = BufferGeometry().apply { override fun build(): BufferGeometry = BufferGeometry().apply {
//setIndex(Int16BufferAttribute(indices.toShortArray(), 1)) //setIndex(Int16BufferAttribute(indices.toShortArray(), 1))
setIndex(indices.toTypedArray()) setIndex(indices.toTypedArray())
setAttribute("position", Float32BufferAttribute(positions.toFloatArray(), 3)) setAttribute("position", Float32BufferAttribute(positions.toTypedArray(), 3))
setAttribute("normal", Float32BufferAttribute(normals.toFloatArray(), 3)) setAttribute("normal", Float32BufferAttribute(normals.toTypedArray(), 3))
//setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3)) //setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3))
computeBoundingSphere() computeBoundingSphere()

View File

@ -32,12 +32,9 @@ external class CSG {
fun toMesh(csg: CSG, toMatrix: Matrix4): Mesh fun toMesh(csg: CSG, toMatrix: Matrix4): Mesh
fun iEval(tokens: Mesh, index: Number? = definedExternally) fun iEval(tokens: Mesh, index: Number? = definedExternally)
fun eval(tokens: Mesh, doRemove: Boolean): Mesh fun eval(tokens: Mesh, doRemove: Boolean): Mesh
var _tmpm3: Any fun union(meshA: Mesh, meshB: Mesh): Mesh
var doRemove: Any fun subtract(meshA: Mesh, meshB: Mesh): Mesh
var currentOp: Any fun intersect(meshA: Mesh, meshB: Mesh): Mesh
var currentPrim: Any
var nextPrim: Any
var sourceMesh: Any
} }
} }