Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separated to two constructors #346

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions sceneview/src/main/java/io/github/sceneview/node/CubeNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ open class CubeNode(
engine: Engine,
size: Size = Cube.DEFAULT_SIZE,
center: Position = Cube.DEFAULT_CENTER,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance? = null,
/**
* Binds a material instance to the specified primitive.
*
Expand All @@ -25,7 +21,7 @@ open class CubeNode(
* Should return the material to bind for the zero-based index of the primitive, must be less
* than the [Geometry.submeshes] size passed to constructor.
*/
materialInstances: (index: Int) -> MaterialInstance? = { materialInstance },
materialInstances: (index: Int) -> MaterialInstance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why moving it to non nullable?
It could be usefull in case only some faces requiring material.
Same for every Geometries they could be used for collision purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought a face must be attached with a material. It is fixed now.

/**
* The parent node.
*
Expand All @@ -48,6 +44,26 @@ open class CubeNode(
parent = parent,
renderableApply = renderableApply
) {

constructor(
engine: Engine,
size: Size = Cube.DEFAULT_SIZE,
center: Position = Cube.DEFAULT_CENTER,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also be nullable for every geometries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

parent: Node? = null,
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : this(
engine = engine,
size = size,
center = center,
materialInstances = { materialInstance },
parent = parent,
renderableApply = renderableApply
)

val center get() = geometry.center
val size get() = geometry.size

Expand Down
39 changes: 29 additions & 10 deletions sceneview/src/main/java/io/github/sceneview/node/CylinderNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ import io.github.sceneview.math.Position

open class CylinderNode(
engine: Engine,
radius: Float,
height: Float,
center: Position,
sideCount: Int,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance? = null,
radius: Float = Cylinder.DEFAULT_RADIUS,
height: Float = Cylinder.DEFAULT_HEIGHT,
center: Position = Cylinder.DEFAULT_CENTER,
sideCount: Int = Cylinder.DEFAULT_SIDE_COUNT,
/**
* Binds a material instance to the specified primitive.
*
Expand All @@ -26,7 +22,7 @@ open class CylinderNode(
* Should return the material to bind for the zero-based index of the primitive, must be less
* than the [Geometry.submeshes] size passed to constructor.
*/
materialInstances: (index: Int) -> MaterialInstance? = { materialInstance },
materialInstances: (index: Int) -> MaterialInstance,
/**
* The parent node.
*
Expand All @@ -46,11 +42,34 @@ open class CylinderNode(
.center(center)
.sideCount(sideCount)
.build(engine),
materialInstance = materialInstance,
materialInstances = materialInstances,
parent = parent,
renderableApply = renderableApply
) {

constructor(
engine: Engine,
radius: Float = Cylinder.DEFAULT_RADIUS,
height: Float = Cylinder.DEFAULT_HEIGHT,
center: Position = Cylinder.DEFAULT_CENTER,
sideCount: Int = Cylinder.DEFAULT_SIDE_COUNT,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance,
parent: Node? = null,
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : this(
engine = engine,
radius = radius,
height = height,
center = center,
sideCount = sideCount,
materialInstances = { materialInstance },
parent = parent,
renderableApply = renderableApply
)

val radius get() = geometry.radius
val height get() = geometry.height
val center get() = geometry.center
Expand Down
53 changes: 40 additions & 13 deletions sceneview/src/main/java/io/github/sceneview/node/GeometryNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ open class GeometryNode(
engine: Engine,
vertices: List<Geometry.Vertex> = listOf(),
submeshes: List<Geometry.Submesh> = listOf(),
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance? = null,
/**
* Binds a material instance to the specified primitive.
*
Expand All @@ -49,7 +45,7 @@ open class GeometryNode(
* Should return the material to bind for the zero-based index of the primitive, must be less
* than the [Geometry.submeshes] size passed to constructor.
*/
materialInstances: (index: Int) -> MaterialInstance? = { materialInstance },
materialInstances: (index: Int) -> MaterialInstance,
/**
* The parent node.
*
Expand All @@ -67,12 +63,30 @@ open class GeometryNode(
.vertices(vertices)
.submeshes(submeshes)
.build(engine),
materialInstance = materialInstance,
materialInstances = materialInstances,
parent = parent,
renderableApply = renderableApply
) {
val vertexBuffer get() = geometry.vertexBuffer

constructor(
engine: Engine,
vertices: List<Geometry.Vertex> = listOf(),
submeshes: List<Geometry.Submesh> = listOf(),
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance,
parent: Node? = null,
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : this(
engine = engine,
vertices = vertices,
submeshes = submeshes,
materialInstances = { materialInstance },
parent = parent,
renderableApply = renderableApply
)

val indexBuffer get() = geometry.indexBuffer

fun setVertices(vertices: List<Geometry.Vertex>) = geometry.setVertices(vertices)
Expand All @@ -82,10 +96,6 @@ open class GeometryNode(
open class BaseGeometryNode<T : Geometry>(
engine: Engine,
val geometry: T,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance? = null,
/**
* Binds a material instance to the specified primitive.
*
Expand All @@ -95,7 +105,7 @@ open class BaseGeometryNode<T : Geometry>(
* Should return the material to bind for the zero-based index of the primitive, must be less
* than the [Geometry.submeshes] size passed to constructor.
*/
materialInstances: (index: Int) -> MaterialInstance? = { materialInstance },
materialInstances: (index: Int) -> MaterialInstance,
/**
* The parent node.
*
Expand All @@ -109,12 +119,29 @@ open class BaseGeometryNode<T : Geometry>(
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : RenderableNode(engine = engine, parent = parent) {

constructor(
engine: Engine,
geometry: T,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance,
parent: Node? = null,
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : this(
engine = engine,
geometry = geometry,
materialInstances = { materialInstance },
parent = parent,
renderableApply = renderableApply
)

init {
RenderableManager.Builder(geometry.submeshes.size)
.geometry(geometry)
.apply {
geometry.submeshes.forEachIndexed { index, _ ->
materialInstances(index)?.let { material(index, it) }
material(index, materialInstances(index))
}
}
.apply(renderableApply)
Expand Down
29 changes: 23 additions & 6 deletions sceneview/src/main/java/io/github/sceneview/node/PlaneNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ open class PlaneNode(
size: Size = Plane.DEFAULT_SIZE,
center: Position = Plane.DEFAULT_CENTER,
normal: Direction = Plane.DEFAULT_NORMAL,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance? = null,
/**
* Binds a material instance to the specified primitive.
*
Expand All @@ -27,7 +23,7 @@ open class PlaneNode(
* Should return the material to bind for the zero-based index of the primitive, must be less
* than the [Geometry.submeshes] size passed to constructor.
*/
materialInstances: (index: Int) -> MaterialInstance? = { materialInstance },
materialInstances: (index: Int) -> MaterialInstance,
/**
* The parent node.
*
Expand All @@ -46,11 +42,32 @@ open class PlaneNode(
.center(center)
.normal(normal)
.build(engine),
materialInstance = materialInstance,
materialInstances = materialInstances,
parent = parent,
renderableApply = renderableApply
) {

constructor(
engine: Engine,
size: Size = Plane.DEFAULT_SIZE,
center: Position = Plane.DEFAULT_CENTER,
normal: Direction = Plane.DEFAULT_NORMAL,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance,
parent: Node? = null,
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : this(
engine = engine,
size = size,
center = center,
normal = normal,
materialInstances = { materialInstance },
parent = parent,
renderableApply = renderableApply
)

val size get() = geometry.size
val center get() = geometry.center
val normal get() = geometry.normal
Expand Down
39 changes: 29 additions & 10 deletions sceneview/src/main/java/io/github/sceneview/node/SphereNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ import io.github.sceneview.math.Position

open class SphereNode(
engine: Engine,
radius: Float,
center: Position,
stacks: Int,
slices: Int,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance? = null,
radius: Float = Sphere.DEFAULT_RADIUS,
center: Position = Sphere.DEFAULT_CENTER,
stacks: Int = Sphere.DEFAULT_STACKS,
slices: Int = Sphere.DEFAULT_SLICES,
/**
* Binds a material instance to the specified primitive.
*
Expand All @@ -26,7 +22,7 @@ open class SphereNode(
* Should return the material to bind for the zero-based index of the primitive, must be less
* than the [Geometry.submeshes] size passed to constructor.
*/
materialInstances: (index: Int) -> MaterialInstance? = { materialInstance },
materialInstances: (index: Int) -> MaterialInstance,
/**
* The parent node.
*
Expand All @@ -46,11 +42,34 @@ open class SphereNode(
.stacks(stacks)
.slices(slices)
.build(engine),
materialInstance = materialInstance,
materialInstances = materialInstances,
parent = parent,
renderableApply = renderableApply
) {

constructor(
engine: Engine,
radius: Float = Sphere.DEFAULT_RADIUS,
center: Position = Sphere.DEFAULT_CENTER,
stacks: Int = Sphere.DEFAULT_STACKS,
slices: Int = Sphere.DEFAULT_SLICES,
/**
* Binds a material instance to all primitives.
*/
materialInstance: MaterialInstance,
parent: Node? = null,
renderableApply: RenderableManager.Builder.() -> Unit = {}
) : this(
engine = engine,
radius = radius,
center = center,
stacks = stacks,
slices = slices,
materialInstances = { materialInstance },
parent = parent,
renderableApply = renderableApply
)

val radius get() = geometry.radius
val center get() = geometry.center
val stacks get() = geometry.stacks
Expand Down
Loading