Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: structureio/StructureKit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.4
Choose a base ref
...
head repository: structureio/StructureKit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 4 files changed
  • 3 contributors

Commits on Feb 6, 2024

  1. Update README.md

    a-tokar authored Feb 6, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    008f2d6 View commit details
  2. Merge pull request #2 from structureio/update-readme

    Update README.md
    a-tokar authored Feb 6, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    85b732e View commit details

Commits on Dec 16, 2024

  1. (+) draw holes and render transparent mesh

    - Add STKPoint3D for receiving hole vertices
    - modified depth stencil function for transparent solid mode
    - added transparent solid mesh rendering style
    - added variables to render lines. Lines are rendered using the thick line renderer.
    Kazi Miftahul committed Dec 16, 2024
    Copy the full SHA
    03a72e6 View commit details

Commits on Dec 18, 2024

  1. (-) remove custom object to receive hole vertices

    Kazi Miftahul committed Dec 18, 2024
    Copy the full SHA
    840e2b4 View commit details

Commits on Dec 19, 2024

  1. (-) remove extra shader object

    Kazi Miftahul committed Dec 19, 2024
    Copy the full SHA
    4d34d43 View commit details

Commits on Jan 10, 2025

  1. Merge pull request #4 from structureio/feature/render-holes

    (+) draw holes and render transparent mesh
    kazi-mifta authored Jan 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2e3792f View commit details
Showing with 49 additions and 8 deletions.
  1. +1 −1 README.md
  2. +16 −3 Sources/StructureKit/Metal/STKMeshRenderers.swift
  3. +30 −2 Sources/StructureKit/Metal/STKMetalRenderer.swift
  4. +2 −2 Sources/StructureKit/STKCommon.swift
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import StructureKit
### Integration with Structure SDK
StructureKit based on Structure SDK - compatible interfaces.

Current version is compatible with Structure SDK `2.*`
Current version is compatible with Structure SDK `2.*` and `3.*`.

To seamlessly use Structure SDK types together with StructureKit, add the following code in your project:

19 changes: 16 additions & 3 deletions Sources/StructureKit/Metal/STKMeshRenderers.swift
Original file line number Diff line number Diff line change
@@ -87,7 +87,8 @@ public class STKMeshRendererSolid: STKShader {
node: STKDrawableObject,
worldModelMatrix: float4x4,
projectionMatrix: float4x4,
color: vector_float4 = vector_float4(1, 1, 1, 1)
color: vector_float4 = vector_float4(1, 1, 1, 1),
hideBackFaces: Bool = true
) {
guard node.vertexType is GLKVector3,
node.indexType is UInt32
@@ -102,7 +103,10 @@ public class STKMeshRendererSolid: STKShader {

commandEncoder.pushDebugGroup("RenderMeshLightedGrey")

commandEncoder.setDepthStencilState(depthStencilState)
// Setting the depth stencil state to prevent rendering the back faces, otherwise it renders the backfaces and mesh apprears transparent
if hideBackFaces {
commandEncoder.setDepthStencilState(depthStencilState)
}
commandEncoder.setRenderPipelineState(pipelineState)

// buffers
@@ -554,7 +558,7 @@ public class STKMeshRendererLines: STKShader {
public class STKScanMeshRenderer {
private var solid: STKMeshRendererSolid
private var wireframe: STKMeshRendererWireframe

public init(view: MTKView, device: MTLDevice) {
solid = STKShaderManager.solid
wireframe = STKShaderManager.wireframe
@@ -589,6 +593,15 @@ public class STKScanMeshRenderer {
projectionMatrix: projectionMatrix,
useXray: false,
color: color)
case .transparentSolid:
solid.render(
commandEncoder,
node: node,
worldModelMatrix: modelViewMatrix,
projectionMatrix: projectionMatrix,
color: color,
hideBackFaces: false
)
}
}

32 changes: 30 additions & 2 deletions Sources/StructureKit/Metal/STKMetalRenderer.swift
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ import MetalKit

public enum STKMeshRenderingStyle {
case solid
case transparentSolid
case wireframe
}

@@ -152,6 +153,7 @@ public class STKMetalRenderer: NSObject, STKRenderer {
// data to visualize
private var _scanMesh: STKMeshBuffers
private var _arkitMesh: STKMeshBuffers
private var _lines: [STKMeshBuffers] = []
private var _anchors: [simd_float4x4] = []
private var _volumeSize = simd_float3(1, 1, 1)
private var colorCameraGLProjectionMatrix = float4x4.identity
@@ -168,7 +170,8 @@ public class STKMetalRenderer: NSObject, STKRenderer {
private var _anchorRenderer: STKLineRenderer
private var _depthOverlayRenderer: STKDepthRenderer
private var _meshRenderer: STKScanMeshRenderer

private var _thickLineRenderer: STKMeshRendererThickLines

// rendering state
private var _commandEncoder: MTLRenderCommandEncoder?
private var _commandBuffer: MTLCommandBuffer?
@@ -213,6 +216,7 @@ public class STKMetalRenderer: NSObject, STKRenderer {
_anchorRenderer = STKLineRenderer(view: view, device: device)
_depthOverlayRenderer = STKDepthRenderer(view: view, device: device)
_meshRenderer = STKScanMeshRenderer(view: view, device: device)
_thickLineRenderer = STKMeshRendererThickLines(view: view, device: device)

_scanMesh = STKMeshBuffers(_device)
_scanMesh.mesh = mesh
@@ -235,7 +239,21 @@ public class STKMetalRenderer: NSObject, STKRenderer {
public func setARKitMesh(_ mesh: ARFaceGeometry) { _arkitMesh.updateMesh(arkitFace: mesh) }

public func setARKitAnchors(_ anchors: [simd_float4x4]) { _anchors = anchors }


public func setLines(verticesList: inout [[vector_float3]], color: vector_float3 = vector_float3(0,1,0)) {
_lines.removeAll(keepingCapacity: true)
_lines.reserveCapacity(verticesList.count)
if (verticesList.count > 0)
{
for vertices in verticesList {
var thickLineBuffer = STKMeshBuffers(MTLCreateSystemDefaultDevice()!)

thickLineBuffer.update(thickLine: vertices, colors: [vector_float3](repeating: color, count: vertices.count))
_lines.append(thickLineBuffer)
}
}
}

public func adjustCubeSize(_ sizeInMeters: simd_float3) { _volumeSize = sizeInMeters }

public func setARKitTransformation(_ transformation: simd_float4x4) { _arkitRenderer.arkitToWorld = transformation }
@@ -334,6 +352,16 @@ public class STKMetalRenderer: NSObject, STKRenderer {
color: color,
style: style)
}

public func renderThickLines(
cameraPose: simd_float4x4, orientation: simd_float4x4) {
guard let commandEncoder = _commandEncoder else { return }
let worldModelMat = cameraPose.inverse
let projectionMat = orientation * projection
for line in _lines {
_thickLineRenderer.render(commandEncoder, node: line, worldModelMatrix: worldModelMat, projectionMatrix: projectionMat)
}
}

public func renderARKitMesh(cameraPose: simd_float4x4, orientation: simd_float4x4) {
guard let commandEncoder = _commandEncoder else { return }
4 changes: 2 additions & 2 deletions Sources/StructureKit/STKCommon.swift
Original file line number Diff line number Diff line change
@@ -211,10 +211,10 @@ extension MTLRenderPipelineDescriptor {

}

public func makeDepthStencilState(_ device: MTLDevice) -> MTLDepthStencilState {
public func makeDepthStencilState(_ device: MTLDevice, isDepthWriteEnabled: Bool = true) -> MTLDepthStencilState {
let depthStencilDescriptor = MTLDepthStencilDescriptor()
depthStencilDescriptor.depthCompareFunction = .less
depthStencilDescriptor.isDepthWriteEnabled = true
depthStencilDescriptor.isDepthWriteEnabled = isDepthWriteEnabled
return device.makeDepthStencilState(descriptor: depthStencilDescriptor)!
}