The objective of this pull request is to implement csg, which allows complex geometric figures to be created from boolean operations of union, difference and intersection. The history of this pull request is very dense with commits because it was opened at a fairly early stage of PhotoNim's development and therefore has commits linked to different versions and code logics. The situation now in master with regard to csg is as follows:
[x] csgUnion
[ ] csgDiff
[ ] csgInt
Actually, during the development of PhotoNim (and in particular within this pull request) there was a time when all three types of csg were present: those are images produced using PhotoNim and actually committed.
The change tree traversal modality using getClosestHit made the old implementation incompatible with the state of the art of PhotoNim. As a result, we aim in the future to make the ability to create csgInt and csgDiff usable again for the user. Let's first look at the old implementation:
Shape* = ref object
material*: Material
case kind*: ShapeKind
of skAABox:
aabb*: Interval[Point3D]
of skTriangle:
vertices*: array[3, Point3D]
of skSphere:
radius*: float32
of skEllipsoid:
axis*: tuple[a: float32, b: float32, c: float32]
of skCylinder:
R*, phiMax*: float32
zSpan*: Interval[float32]
of skPlane: discard
of skTriangularMesh:
nodes*: seq[Point3D]
edges*: seq[int]
tree*: SceneNode
of skCSGUnion, skCSGInt, skCSGDiff:
shapes*: tuple[primary, secondary: Shape]
shTrans*: tuple[tPrimary, tSecondary: Transformation]
CSGs where a shape kind, which is not a case in version 1.0.0 PhotoNim. In order to create a csg object, it was necessary to work with recursive calls, as a csg shape actually consisted of two shapes and two transformations (the local shapes) of which the first had all privileges. In order to get hits, we used getHitPayload and getAllHitPayload such as following, where we report only the code regarding CSGs.
To bring these functions into the code we imagine that it is necessary to define a function that returns all the hit times, one that allows you to evaluate whether a point is inside a shape or not and work to evaluate all the intersections, in order to be able to choose the correct ones for the desired rendering.
The objective of this pull request is to implement csg, which allows complex geometric figures to be created from boolean operations of union, difference and intersection. The history of this pull request is very dense with commits because it was opened at a fairly early stage of PhotoNim's development and therefore has commits linked to different versions and code logics. The situation now in master with regard to csg is as follows:
Actually, during the development of PhotoNim (and in particular within this pull request) there was a time when all three types of csg were present: those are images produced using PhotoNim and actually committed.
The change tree traversal modality using getClosestHit made the old implementation incompatible with the state of the art of PhotoNim. As a result, we aim in the future to make the ability to create csgInt and csgDiff usable again for the user. Let's first look at the old implementation:
CSGs where a shape kind, which is not a case in version 1.0.0 PhotoNim. In order to create a csg object, it was necessary to work with recursive calls, as a csg shape actually consisted of two shapes and two transformations (the local shapes) of which the first had all privileges. In order to get hits, we used
getHitPayload
andgetAllHitPayload
such as following, where we report only the code regarding CSGs.To bring these functions into the code we imagine that it is necessary to define a function that returns all the hit times, one that allows you to evaluate whether a point is inside a shape or not and work to evaluate all the intersections, in order to be able to choose the correct ones for the desired rendering.