v0.2.0-dev-22 #47
@ -223,7 +223,7 @@ abstract external class BufferAttribute protected constructor(
|
||||
|
||||
|
||||
external class Float32BufferAttribute(
|
||||
array: FloatArray,
|
||||
array: Array<Float>,
|
||||
itemSize: Int,
|
||||
normalized: Boolean = definedExternally
|
||||
) : BufferAttribute
|
||||
|
@ -36,7 +36,7 @@ import info.laht.threekt.materials.Material
|
||||
|
||||
open external class Mesh(geometry: BufferGeometry?, material: Material?) : Object3D {
|
||||
|
||||
var geometry: dynamic
|
||||
var geometry: BufferGeometry
|
||||
var material: Material
|
||||
|
||||
var drawMode: Int
|
||||
|
@ -36,7 +36,8 @@ public abstract class MeshThreeFactory<in T : Solid>(
|
||||
matrixAutoUpdate = false
|
||||
//set position for mesh
|
||||
updatePosition(obj)
|
||||
}.applyProperties(obj)
|
||||
applyProperties(obj)
|
||||
}
|
||||
|
||||
//add listener to object properties
|
||||
obj.onPropertyChange(three.updateScope) { name ->
|
||||
|
@ -1,30 +1,60 @@
|
||||
package space.kscience.visionforge.solid.three
|
||||
|
||||
import CSG
|
||||
import info.laht.threekt.core.BufferGeometry
|
||||
import info.laht.threekt.math.Matrix4
|
||||
import info.laht.threekt.core.Object3D
|
||||
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.CompositeType
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* 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")
|
||||
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 when (obj.compositeType) {
|
||||
CompositeType.UNION -> CSG.union(first,second)
|
||||
CompositeType.INTERSECT -> CSG.intersect(first,second)
|
||||
CompositeType.SUBTRACT -> CSG.subtract(first,second)
|
||||
}.apply {
|
||||
updatePosition(obj)
|
||||
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())
|
||||
}
|
||||
|
||||
}
|
@ -52,8 +52,8 @@ public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
||||
override fun build(): BufferGeometry = BufferGeometry().apply {
|
||||
//setIndex(Int16BufferAttribute(indices.toShortArray(), 1))
|
||||
setIndex(indices.toTypedArray())
|
||||
setAttribute("position", Float32BufferAttribute(positions.toFloatArray(), 3))
|
||||
setAttribute("normal", Float32BufferAttribute(normals.toFloatArray(), 3))
|
||||
setAttribute("position", Float32BufferAttribute(positions.toTypedArray(), 3))
|
||||
setAttribute("normal", Float32BufferAttribute(normals.toTypedArray(), 3))
|
||||
//setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3))
|
||||
|
||||
computeBoundingSphere()
|
||||
|
@ -32,12 +32,9 @@ external class CSG {
|
||||
fun toMesh(csg: CSG, toMatrix: Matrix4): Mesh
|
||||
fun iEval(tokens: Mesh, index: Number? = definedExternally)
|
||||
fun eval(tokens: Mesh, doRemove: Boolean): Mesh
|
||||
var _tmpm3: Any
|
||||
var doRemove: Any
|
||||
var currentOp: Any
|
||||
var currentPrim: Any
|
||||
var nextPrim: Any
|
||||
var sourceMesh: Any
|
||||
fun union(meshA: Mesh, meshB: Mesh): Mesh
|
||||
fun subtract(meshA: Mesh, meshB: Mesh): Mesh
|
||||
fun intersect(meshA: Mesh, meshB: Mesh): Mesh
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user