diff --git a/GLLara.xcodeproj/project.pbxproj b/GLLara.xcodeproj/project.pbxproj index 2f8cd2f..8d3a020 100644 --- a/GLLara.xcodeproj/project.pbxproj +++ b/GLLara.xcodeproj/project.pbxproj @@ -231,6 +231,7 @@ 5272709C2BE77A7D00EE52B5 /* GLLTexture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5272709A2BE600C300EE52B5 /* GLLTexture.swift */; }; 527270A32BE7E0F100EE52B5 /* GLLItem+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527270A12BE7E0F100EE52B5 /* GLLItem+Extensions.swift */; }; 527270A52BE8064100EE52B5 /* GLLDataReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C3AD8D29A2241E002EC334 /* GLLDataReader.swift */; }; + 527270A72BE810A600EE52B5 /* GLLItemMesh+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527270A62BE810A600EE52B5 /* GLLItemMesh+Extensions.swift */; }; 5274446427FCC9C100E5A3FD /* GLLModelMesh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5274446327FCC9C100E5A3FD /* GLLModelMesh.swift */; }; 5274446627FD64F000E5A3FD /* GLLModelMeshObj.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5274446527FD64F000E5A3FD /* GLLModelMeshObj.swift */; }; 5274446827FD6F7F00E5A3FD /* GLLVertexAttribAccessorSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5274446727FD6F7F00E5A3FD /* GLLVertexAttribAccessorSet.swift */; }; @@ -672,6 +673,7 @@ 526E0F9B1C169E3500F198BF /* testStaticTRUDiffuseLightmap.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = testStaticTRUDiffuseLightmap.png; sourceTree = ""; }; 5272709A2BE600C300EE52B5 /* GLLTexture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLTexture.swift; sourceTree = ""; }; 527270A12BE7E0F100EE52B5 /* GLLItem+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GLLItem+Extensions.swift"; sourceTree = ""; }; + 527270A62BE810A600EE52B5 /* GLLItemMesh+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GLLItemMesh+Extensions.swift"; sourceTree = ""; }; 5274446327FCC9C100E5A3FD /* GLLModelMesh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLModelMesh.swift; sourceTree = ""; }; 5274446527FD64F000E5A3FD /* GLLModelMeshObj.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLModelMeshObj.swift; sourceTree = ""; }; 5274446727FD6F7F00E5A3FD /* GLLVertexAttribAccessorSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLVertexAttribAccessorSet.swift; sourceTree = ""; }; @@ -1371,6 +1373,7 @@ 5214470916DBF206003E260F /* GLLItemMesh+MeshExport.swift */, 5214470C16DC2312003E260F /* GLLItem+MeshExport.swift */, 521102EE2899C430001BE4BC /* GLLItemBoneExtensions.swift */, + 527270A62BE810A600EE52B5 /* GLLItemMesh+Extensions.swift */, ); name = "Scene members"; sourceTree = ""; @@ -1910,6 +1913,7 @@ 527270A32BE7E0F100EE52B5 /* GLLItem+Extensions.swift in Sources */, 52D3D72916029BD9006CB743 /* GLLRenderAccessoryViewController.m in Sources */, 52CE280C1605FE98005A86E9 /* GLLLogarithmicValueTransformer.m in Sources */, + 527270A72BE810A600EE52B5 /* GLLItemMesh+Extensions.swift in Sources */, 5275F6821607293000978779 /* GLLItemController.m in Sources */, 52C516FF2871998C000EB8C2 /* GLLPipelineStateInformation.swift in Sources */, 5275F6891607399800978779 /* GLLItemListController.m in Sources */, diff --git a/GLLara/GLLItemMesh+Extensions.swift b/GLLara/GLLItemMesh+Extensions.swift new file mode 100644 index 0000000..ec45ba5 --- /dev/null +++ b/GLLara/GLLItemMesh+Extensions.swift @@ -0,0 +1,37 @@ +// +// GLLItemMesh+Extensions.swift +// GLLara +// +// Created by Torsten Kammer on 05.05.24. +// Copyright © 2024 Torsten Kammer. All rights reserved. +// + +import Foundation + +extension GLLItemMesh { + @objc func renderParameter(name: String) -> GLLRenderParameter? { + return renderParameters.first { $0.name == name } + } + + @objc func texture(identifier: String) -> GLLItemMeshTexture? { + return textures.first { $0.identifier == identifier } + } + + @objc var isUsingBlending: Bool { + get { + if isCustomBlending { + return isBlended + } else { + return mesh.usesAlphaBlending + } + } + set { + isCustomBlending = true + isBlended = newValue + } + } + + @objc var mesh: GLLModelMesh { + return item.model.meshes[Int(meshIndex)] + } +} diff --git a/GLLara/GLLItemMesh+MeshExport.swift b/GLLara/GLLItemMesh+MeshExport.swift index 3fcfc01..f813e6c 100644 --- a/GLLara/GLLItemMesh+MeshExport.swift +++ b/GLLara/GLLItemMesh+MeshExport.swift @@ -43,7 +43,7 @@ extension GLLItemMesh { // 3 - write required parameters for parameterNames in shaderDescription.parameterUniformsInOrder { - let param = renderParameter(withName: parameterNames[0]) as! GLLFloatRenderParameter + let param = renderParameter(name: parameterNames[0]) as! GLLFloatRenderParameter name += "_\(param.value)" } @@ -51,7 +51,7 @@ extension GLLItemMesh { } private func textureUrls(description: XnaLaraShaderDescription) -> [URL] { - return description.textureUniformsInOrder.map { texture(withIdentifier: $0).textureURL! as URL } + return description.textureUniformsInOrder.map { texture(identifier: $0)!.textureURL! as URL } } func writeASCII() throws -> String { diff --git a/GLLara/GLLItemMesh.h b/GLLara/GLLItemMesh.h index a137714..e7f95ce 100644 --- a/GLLara/GLLItemMesh.h +++ b/GLLara/GLLItemMesh.h @@ -53,11 +53,6 @@ // Called only internally and from child objects, in case some setting changed that requires a shader recompile - (void)updateShader; -@property (nonatomic) BOOL isUsingBlending; - -- (GLLRenderParameter *)renderParameterWithName:(NSString *)parameterName; -- (GLLItemMeshTexture *)textureWithIdentifier:(NSString *)textureIdentifier; - @end @interface GLLItemMesh (CoreDataGeneratedAccessors) diff --git a/GLLara/GLLItemMesh.m b/GLLara/GLLItemMesh.m index a184a3e..0d4a9db 100644 --- a/GLLara/GLLItemMesh.m +++ b/GLLara/GLLItemMesh.m @@ -17,9 +17,6 @@ #import "GLLara-Swift.h" @interface GLLItemMesh () -{ - __weak GLLModelMesh *underlyingMesh; -} /*! * Creates the GLLShaderData object for this mesh, given the current values. @@ -48,7 +45,6 @@ @implementation GLLItemMesh @dynamic mesh; @dynamic meshIndex; @dynamic displayName; -@dynamic isUsingBlending; @synthesize shader; @@ -264,40 +260,6 @@ - (NSUInteger)meshIndex return [self.item.meshes indexOfObject:self]; } -- (GLLModelMesh *)mesh -{ - if (!underlyingMesh) - underlyingMesh = self.item.model.meshes[self.meshIndex]; - return underlyingMesh; -} - -- (GLLRenderParameter *)renderParameterWithName:(NSString *)parameterName; -{ - return [self.renderParameters anyObjectMatching:^BOOL(GLLRenderParameter *parameter){ - return [parameter.name isEqual:parameterName]; - }]; -} -- (GLLItemMeshTexture *)textureWithIdentifier:(NSString *)textureIdentifier; -{ - return [self.textures anyObjectMatching:^BOOL(GLLItemMeshTexture *texture){ - return [texture.identifier isEqual:textureIdentifier]; - }]; -} - -- (BOOL)isUsingBlending -{ - if (self.isCustomBlending) - return self.isBlended; - else - return self.mesh.usesAlphaBlending; -} - -- (void)setIsUsingBlending:(BOOL)isUsingBlending -{ - self.isCustomBlending = YES; - self.isBlended = isUsingBlending; -} - #pragma mark - Private - (GLLShaderData *)_createShaderData { diff --git a/GLLara/GLLItemMeshState.swift b/GLLara/GLLItemMeshState.swift index e8642ee..3e75f08 100644 --- a/GLLara/GLLItemMeshState.swift +++ b/GLLara/GLLItemMeshState.swift @@ -117,7 +117,7 @@ class GLLItemMeshState { } private func loadTexture(identifier: String) async throws -> GLLTexture { - let textureAssignment = itemMesh.texture(withIdentifier: identifier) + let textureAssignment = itemMesh.texture(identifier: identifier) if let url = textureAssignment?.textureURL { // Load from the given URL (where possible @@ -156,7 +156,7 @@ class GLLItemMeshState { } private func parameterColor(name: String, defaultValue: SIMD4) -> SIMD4 { - guard let parameter = itemMesh.renderParameter(withName: name) else { + guard let parameter = itemMesh.renderParameter(name: name) else { return defaultValue } @@ -169,7 +169,7 @@ class GLLItemMeshState { } private func parameterFloat(name: String, defaultValue: Float32) -> Float32 { - guard let parameter = itemMesh.renderParameter(withName: name) else { + guard let parameter = itemMesh.renderParameter(name: name) else { return defaultValue } @@ -240,7 +240,7 @@ class GLLItemMeshState { } private func displayUrl(for identifier: String) -> URL? { - let textureAssignment = itemMesh.texture(withIdentifier: identifier) + let textureAssignment = itemMesh.texture(identifier: identifier) if let url = textureAssignment?.textureURL { // Use URL in model @@ -301,7 +301,7 @@ class GLLItemMeshState { var texCoordAssignments: [Int: Int] = [:] for identifier in shader.textureUniforms { let index = textureIndex(for: identifier) - if let assignment = itemMesh.texture(withIdentifier: identifier) { + if let assignment = itemMesh.texture(identifier: identifier) { if (assignment.texCoordSet < 0) { if let texture = itemMesh.mesh.textures[identifier], texture.texCoordSet > 0 { texCoordAssignments[index] = min(texture.texCoordSet, itemMesh.mesh.countOfUVLayers - 1) diff --git a/GLLara/GLLRenderParameterSelectionPlaceholder.m b/GLLara/GLLRenderParameterSelectionPlaceholder.m index 081e708..9efb48c 100644 --- a/GLLara/GLLRenderParameterSelectionPlaceholder.m +++ b/GLLara/GLLRenderParameterSelectionPlaceholder.m @@ -10,6 +10,7 @@ #import "GLLItemMesh.h" #import "GLLRenderParameter.h" +#import "GLLara-Swift.h" @interface GLLRenderParameterSelectionPlaceholder () diff --git a/GLLara/NSArray+Map.h b/GLLara/NSArray+Map.h index e48ebcf..84f650d 100644 --- a/GLLara/NSArray+Map.h +++ b/GLLara/NSArray+Map.h @@ -13,14 +13,12 @@ - (NSArray *)map:(id (^)(ObjectType))block; - (NSMutableArray *)mapMutable:(id (^)(ObjectType))block; - (NSArray *)mapAndJoin:(NSArray *(^)(id))block; -- (ObjectType)firstObjectMatching:(BOOL(^)(ObjectType))predicate; @end @interface NSOrderedSet<__covariant ObjectType> (Map) - (NSArray *)map:(id (^)(ObjectType))block; -- (ObjectType)firstObjectMatching:(BOOL(^)(ObjectType))predicate; @end @@ -34,7 +32,6 @@ @interface NSSet<__covariant ObjectType> (Map) - (NSArray *)map:(id (^)(ObjectType))block; -- (ObjectType)anyObjectMatching:(BOOL(^)(ObjectType))predicate; @end diff --git a/GLLara/NSArray+Map.m b/GLLara/NSArray+Map.m index 0cf178a..7e47253 100644 --- a/GLLara/NSArray+Map.m +++ b/GLLara/NSArray+Map.m @@ -8,14 +8,6 @@ #import "NSArray+Map.h" -static id firstObjectMatching(id collection, BOOL(^predicate)(id)) -{ - for (id object in collection) - if (predicate(object)) - return object; - return nil; -} - static id mapMutable(id collection, NSUInteger count, id(^function)(id)) { NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:count]; @@ -58,10 +50,6 @@ - (NSArray *)mapAndJoin:(NSArray *(^)(id))block; return result; } -- (id)firstObjectMatching:(BOOL(^)(id))predicate; -{ - return firstObjectMatching(self, predicate); -} @end @@ -71,10 +59,6 @@ - (NSArray *)map:(id (^)(id))block; { return map(self, self.count, block); } -- (id)firstObjectMatching:(BOOL(^)(id))predicate; -{ - return firstObjectMatching(self, predicate); -} @end @@ -84,10 +68,6 @@ - (NSArray *)map:(id (^)(id))block; { return map(self, self.count, block); } -- (id)anyObjectMatching:(BOOL(^)(id))predicate; -{ - return firstObjectMatching(self, predicate); -} @end