Skip to content

Commit abca800

Browse files
committed
Make float4x4.identity a class var
1 parent ff74cd9 commit abca800

File tree

8 files changed

+64
-29
lines changed

8 files changed

+64
-29
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

77
## Unreleased
88

9+
## 1.0.3
10+
11+
### Changed
12+
* `float4x4.identity()` -> `float4x4.identity`
13+
914
## 1.0.2
1015

1116
### Changed
1217
* Enable public entities unintentionally left private
13-
*
1418

1519
## 1.0.1
1620

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You can consume it as a Swift Package:
99
## Usage
1010
Import into your Swift source code:
1111
```swift
12-
import StructurKit
12+
import StructureKit
1313
```
1414

1515
### Integration with Structure SDK

Sources/StructureKit/Metal/STKARKitOverlayRenderer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import StructureKitCTypes
3232

3333
// Draws an ARKit face geometry as a white transparent mesh
3434
public class STKARKitOverlayRenderer {
35-
var arkitToWorld = simd_float4x4()
35+
var arkitToWorld = simd_float4x4.identity
3636
private var depthStencilARKitState: MTLDepthStencilState
3737
private var renderARKitState: MTLRenderPipelineState
3838

Sources/StructureKit/Metal/STKLineRenderer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class STKLineRenderer {
3737
private var indexCubeBuffer: MTLBuffer!
3838
private var indexTriadBuffer: MTLBuffer!
3939
private var mtkView: MTKView
40-
var colorCameraGLProjectionMatrix = float4x4()
41-
var depthCameraGLProjectionMatrix = float4x4()
40+
var colorCameraGLProjectionMatrix = float4x4.identity
41+
var depthCameraGLProjectionMatrix = float4x4.identity
4242

4343
private let cubeVertices4: [simd_float4] = [
4444
simd_float4(0, 0, 0, 1),
@@ -133,7 +133,7 @@ public class STKLineRenderer {
133133

134134
renderAnchors(
135135
commandEncoder,
136-
anchors: [simd_float4x4()],
136+
anchors: [simd_float4x4.identity],
137137
cameraPosition: cameraPosition,
138138
projection: projection,
139139
orientation: orientation,

Sources/StructureKit/Metal/STKMeshBuffers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public class STKMeshBuffers: STKDrawableObject {
217217

218218
public func textureCbCr() -> MTLTexture? { textureCbCrinternal }
219219

220-
public func modelMatrix() -> float4x4 { float4x4() }
220+
public func modelMatrix() -> float4x4 { float4x4.identity }
221221

222222
public func vertexCount() -> Int { nVertex }
223223

Sources/StructureKit/Metal/STKMetalRenderer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public class STKMetalRenderer: NSObject, STKRenderer {
154154
private var _arkitMesh: STKMeshBuffers
155155
private var _anchors: [simd_float4x4] = []
156156
private var _volumeSize = simd_float3(1, 1, 1)
157-
private var colorCameraGLProjectionMatrix = float4x4()
158-
private var depthCameraGLProjectionMatrix = float4x4()
157+
private var colorCameraGLProjectionMatrix = float4x4.identity
158+
private var depthCameraGLProjectionMatrix = float4x4.identity
159159

160160
// metal general
161161
private var _mtkView: MTKView
@@ -297,7 +297,7 @@ public class STKMetalRenderer: NSObject, STKRenderer {
297297
if drawTriad {
298298
_anchorRenderer.renderAnchors(
299299
commandEncoder,
300-
anchors: [simd_float4x4()],
300+
anchors: [simd_float4x4.identity],
301301
cameraPosition: cameraPose,
302302
projection: projection,
303303
orientation: orientation,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// StructureKit - A collection of extension utilities for Structure SDK
2+
// Copyright 2022 XRPro, LLC. All rights reserved.
3+
// http://structure.io
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are met:
7+
//
8+
// * Redistributions of source code must retain the above copyright notice,
9+
// this list of conditions and the following disclaimer.
10+
// * Redistributions in binary form must reproduce the above copyright notice,
11+
// this list of conditions and the following disclaimer in the documentation
12+
// and/or other materials provided with the distribution.
13+
// * Neither the name of XRPro, LLC nor the names of its contributors may be
14+
// used to endorse or promote products derived from this software without
15+
// specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
// POSSIBILITY OF SUCH DAMAGE.
28+
29+
import Metal
30+
31+
public class STKShaderManager {
32+
public static let pixelFormat = MTLPixelFormat.bgra8Unorm
33+
public static let depthFormat = MTLPixelFormat.depth32Float
34+
public static let device = MTLCreateSystemDefaultDevice()!
35+
36+
public static let solid = STKMeshRendererSolid(colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
37+
public static let wireframe = STKMeshRendererWireframe(
38+
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
39+
public static let vertexColor = STKMeshRendererColor(
40+
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
41+
public static let textureShader = STKMeshRendererTexture(
42+
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
43+
public static let pointCloud = STKMeshRendererPoints(
44+
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
45+
public static let lines = STKMeshRendererLines(colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
46+
}

Sources/StructureKit/Metal/STKCommon.swift renamed to Sources/StructureKit/STKCommon.swift

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,6 @@ import StructureKitCTypes
3434

3535
extension String: Error {}
3636

37-
public class STKShaderManager {
38-
public static let pixelFormat = MTLPixelFormat.bgra8Unorm
39-
public static let depthFormat = MTLPixelFormat.depth32Float
40-
public static let device = MTLCreateSystemDefaultDevice()!
41-
42-
public static let solid = STKMeshRendererSolid(colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
43-
public static let wireframe = STKMeshRendererWireframe(
44-
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
45-
public static let vertexColor = STKMeshRendererColor(
46-
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
47-
public static let textureShader = STKMeshRendererTexture(
48-
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
49-
public static let pointCloud = STKMeshRendererPoints(
50-
colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
51-
public static let lines = STKMeshRendererLines(colorFormat: pixelFormat, depthFormat: depthFormat, device: device)
52-
}
53-
5437
extension float4x4 {
5538
public init(_ m: GLKMatrix4) { self = unsafeBitCast(m, to: float4x4.self) }
5639

@@ -61,7 +44,7 @@ extension float4x4 {
6144
return self
6245
}
6346

64-
public static func identity() -> float4x4 { unsafeBitCast(GLKMatrix4Identity, to: float4x4.self) }
47+
public static var identity: float4x4 { unsafeBitCast(GLKMatrix4Identity, to: float4x4.self) }
6548

6649
public static func makeTranslation(_ vec: vector_float3) -> float4x4 {
6750
unsafeBitCast(GLKMatrix4MakeTranslation(vec.x, vec.y, vec.z), to: float4x4.self)
@@ -107,6 +90,8 @@ extension float4x4 {
10790
}
10891

10992
extension float3x3 {
93+
public static var identity: float3x3 { unsafeBitCast(GLKMatrix3Identity, to: float3x3.self) }
94+
11095
public static func makeRotationZ(_ radians: Float) -> float3x3 {
11196
float3x3([
11297
simd_float3(cos(radians), -sin(radians), 0), simd_float3(sin(radians), cos(radians), 0), simd_float3(0, 0, 1),
@@ -231,7 +216,7 @@ public func makeDepthStencilState(_ device: MTLDevice) -> MTLDepthStencilState {
231216
depthStencilDescriptor.depthCompareFunction = .less
232217
depthStencilDescriptor.isDepthWriteEnabled = true
233218
return device.makeDepthStencilState(descriptor: depthStencilDescriptor)!
234-
}
219+
}
235220

236221
public func makePipeline(
237222
_ device: MTLDevice,

0 commit comments

Comments
 (0)