diff --git a/GLLara.xcodeproj/project.pbxproj b/GLLara.xcodeproj/project.pbxproj index 2e0709e..4593c38 100644 --- a/GLLara.xcodeproj/project.pbxproj +++ b/GLLara.xcodeproj/project.pbxproj @@ -75,7 +75,6 @@ 523BBB052880BCB300B2D52E /* GLLGameControllerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523BBB042880BCB300B2D52E /* GLLGameControllerManager.swift */; }; 523BBB072880C78600B2D52E /* GLLPreferenceKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523BBB062880C78600B2D52E /* GLLPreferenceKeys.swift */; }; 523D368116BEB29F004FAD4B /* GLLSubItemController.m in Sources */ = {isa = PBXBuildFile; fileRef = 523D368016BEB29F004FAD4B /* GLLSubItemController.m */; }; - 523D368516BED84B004FAD4B /* GLLItemMeshTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = 523D368416BED84A004FAD4B /* GLLItemMeshTexture.m */; }; 523DE0D61604A14200BB9F61 /* glasses.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 523DE0D51604A14200BB9F61 /* glasses.modelparams.plist */; }; 523DE0E01604A5ED00BB9F61 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52B9E09616027FC800641518 /* Foundation.framework */; }; 523DE0E31604A5ED00BB9F61 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 523DE0E21604A5ED00BB9F61 /* main.m */; }; @@ -273,6 +272,7 @@ 52B6C5212BE2947B005E53CE /* GLLDropTargetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B6C5202BE2947B005E53CE /* GLLDropTargetView.swift */; }; 52B6C5372BE2AB0E005E53CE /* ObjFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B6C5362BE2AB0E005E53CE /* ObjFile.swift */; }; 52B6C5392BE2EB26005E53CE /* MtlFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B6C5382BE2EB26005E53CE /* MtlFile.swift */; }; + 52B6C53C2BE56696005E53CE /* GLLItemMeshTexture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B6C53A2BE5645B005E53CE /* GLLItemMeshTexture.swift */; }; 52B9E0781602086D00641518 /* objFileParameters.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52B9E0771602086D00641518 /* objFileParameters.modelparams.plist */; }; 52B9E0AE1602815800641518 /* RenderParameters.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52B9E0B01602815800641518 /* RenderParameters.strings */; }; 52BB206815F8275E00937450 /* doppelganger.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52BB206715F8275E00937450 /* doppelganger.modelparams.plist */; }; @@ -499,8 +499,6 @@ 523BBB062880C78600B2D52E /* GLLPreferenceKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLPreferenceKeys.swift; sourceTree = ""; }; 523D367F16BEB29F004FAD4B /* GLLSubItemController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLSubItemController.h; sourceTree = ""; }; 523D368016BEB29F004FAD4B /* GLLSubItemController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLSubItemController.m; sourceTree = ""; }; - 523D368316BED849004FAD4B /* GLLItemMeshTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLItemMeshTexture.h; sourceTree = ""; }; - 523D368416BED84A004FAD4B /* GLLItemMeshTexture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLItemMeshTexture.m; sourceTree = ""; }; 523DE0D51604A14200BB9F61 /* glasses.modelparams.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = glasses.modelparams.plist; sourceTree = ""; }; 523DE0DE1604A5ED00BB9F61 /* parseItems */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = parseItems; sourceTree = BUILT_PRODUCTS_DIR; }; 523DE0E21604A5ED00BB9F61 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -748,6 +746,7 @@ 52B6C5202BE2947B005E53CE /* GLLDropTargetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLDropTargetView.swift; sourceTree = ""; }; 52B6C5362BE2AB0E005E53CE /* ObjFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjFile.swift; sourceTree = ""; }; 52B6C5382BE2EB26005E53CE /* MtlFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MtlFile.swift; sourceTree = ""; }; + 52B6C53A2BE5645B005E53CE /* GLLItemMeshTexture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLItemMeshTexture.swift; sourceTree = ""; }; 52B9E0771602086D00641518 /* objFileParameters.modelparams.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = objFileParameters.modelparams.plist; path = ../Shaders/objFileParameters.modelparams.plist; sourceTree = ""; }; 52B9E09616027FC800641518 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 52B9E0AF1602815800641518 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/RenderParameters.strings; sourceTree = ""; }; @@ -1351,6 +1350,7 @@ 5296941F15F4112E00DF2FA3 /* Scene members */ = { isa = PBXGroup; children = ( + 52B6C53A2BE5645B005E53CE /* GLLItemMeshTexture.swift */, 52AF115415FCD4A000DF2565 /* GLLCameraTarget.h */, 52AF115515FCD4A000DF2565 /* GLLCameraTarget.m */, 5291DB9215FBF7BC00ECDBCA /* GLLAmbientLight.h */, @@ -1375,8 +1375,6 @@ 526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.m */, 526AB31A1609C7C300940A74 /* GLLItem+OBJExport.h */, 526AB31B1609C7C300940A74 /* GLLItem+OBJExport.m */, - 523D368316BED849004FAD4B /* GLLItemMeshTexture.h */, - 523D368416BED84A004FAD4B /* GLLItemMeshTexture.m */, 5214470916DBF206003E260F /* GLLItemMesh+MeshExport.swift */, 5214470C16DC2312003E260F /* GLLItem+MeshExport.swift */, 521102EE2899C430001BE4BC /* GLLItemBoneExtensions.swift */, @@ -1913,6 +1911,7 @@ 52B6C5372BE2AB0E005E53CE /* ObjFile.swift in Sources */, 526D5AE62060596000DCDE85 /* GLLNotifications.m in Sources */, 5274447027FE21F100E5A3FD /* GLLModelMesh+OBJExport.swift in Sources */, + 52B6C53C2BE56696005E53CE /* GLLItemMeshTexture.swift in Sources */, 52C9F6201600CCFC003272E1 /* GLLFloatRenderParameter.m in Sources */, 52C9F6231600CCFC003272E1 /* GLLColorRenderParameter.m in Sources */, 52D3D72916029BD9006CB743 /* GLLRenderAccessoryViewController.m in Sources */, @@ -1969,7 +1968,6 @@ 52653D8116BAB729001D802F /* GLLPoseExporter.m in Sources */, 523BBAFF287B23D600B2D52E /* GLLRenderWindow.swift in Sources */, 523D368116BEB29F004FAD4B /* GLLSubItemController.m in Sources */, - 523D368516BED84B004FAD4B /* GLLItemMeshTexture.m in Sources */, 522783B01C0B7FC0002E43FD /* GLLRenderParameterSelectionPlaceholder.m in Sources */, 525BF29B2879E95800E30D48 /* GLLAppDelegate.swift in Sources */, 52F73E9E288BDBA700A580EC /* GLLAmbientLightViewController.swift in Sources */, diff --git a/GLLara/Core Data/GLLSceneModel.xcdatamodeld/GLLSceneModel 5.xcdatamodel/contents b/GLLara/Core Data/GLLSceneModel.xcdatamodeld/GLLSceneModel 5.xcdatamodel/contents index 2627fe6..072bc4b 100644 --- a/GLLara/Core Data/GLLSceneModel.xcdatamodeld/GLLSceneModel 5.xcdatamodel/contents +++ b/GLLara/Core Data/GLLSceneModel.xcdatamodeld/GLLSceneModel 5.xcdatamodel/contents @@ -1,123 +1,108 @@ - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - + - - - - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - + + + + + - + - - + + - - + + - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/GLLara/GLLDocument.m b/GLLara/GLLDocument.m index 9b5dcd6..0c6feaf 100644 --- a/GLLara/GLLDocument.m +++ b/GLLara/GLLDocument.m @@ -18,7 +18,6 @@ #import "GLLItem.h" #import "GLLItemBone.h" #import "GLLItemMesh.h" -#import "GLLItemMeshTexture.h" #import "GLLItem+OBJExport.h" #import "GLLLogarithmicValueTransformer.h" #import "GLLPoseExporter.h" diff --git a/GLLara/GLLItemMesh+MeshExport.swift b/GLLara/GLLItemMesh+MeshExport.swift index 53edac2..f2664ac 100644 --- a/GLLara/GLLItemMesh+MeshExport.swift +++ b/GLLara/GLLItemMesh+MeshExport.swift @@ -51,7 +51,7 @@ extension GLLItemMesh { } private func textureUrls(description: XnaLaraShaderDescription) -> [URL] { - return description.textureUniformsInOrder.map { texture(withIdentifier: $0).textureURL } + return description.textureUniformsInOrder.map { texture(withIdentifier: $0).textureURL as! URL } } func writeASCII() throws -> String { diff --git a/GLLara/GLLItemMesh.m b/GLLara/GLLItemMesh.m index 6e57452..a184a3e 100644 --- a/GLLara/GLLItemMesh.m +++ b/GLLara/GLLItemMesh.m @@ -11,7 +11,6 @@ #import #import "GLLItem.h" -#import "GLLItemMeshTexture.h" #import "GLLRenderParameter.h" #import "NSArray+Map.h" diff --git a/GLLara/GLLItemMeshState.swift b/GLLara/GLLItemMeshState.swift index 6d8627e..66cab90 100644 --- a/GLLara/GLLItemMeshState.swift +++ b/GLLara/GLLItemMeshState.swift @@ -121,7 +121,7 @@ class GLLItemMeshState { if let url = textureAssignment?.textureURL { // Load from the given URL (where possible - return try await drawer.resourceManager.textureAsync(url: url) + return try await drawer.resourceManager.textureAsync(url: url as URL) } else if let data = itemMesh.mesh.textures[identifier]?.data { // Load what the model provided return try GLLTexture(data: data, sourceURL: itemMesh.mesh.model!.baseURL, device: drawer.resourceManager.metalDevice) @@ -244,7 +244,7 @@ class GLLItemMeshState { if let url = textureAssignment?.textureURL { // Use URL in model - return url + return url as URL } else if (itemMesh.mesh.textures[identifier]?.data) != nil { // Use URL of model return itemMesh.mesh.model!.baseURL diff --git a/GLLara/GLLItemMeshTexture.h b/GLLara/GLLItemMeshTexture.h deleted file mode 100644 index a17cd25..0000000 --- a/GLLara/GLLItemMeshTexture.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// GLLItemMeshTexture.h -// GLLara -// -// Created by Torsten Kammer on 03.02.13. -// Copyright (c) 2013 Torsten Kammer. All rights reserved. -// - -#import -#import - -@class GLLItemMesh; -@class GLLTextureDescription; - -/*! - * @abstract Stores which textures are associated with which uniform values. - */ -@interface GLLItemMeshTexture : NSManagedObject - -// URL of the texture -@property (nonatomic, retain) NSURL *textureURL; -@property (nonatomic, retain) NSData * textureBookmarkData; - -// A string identifying the purpose/shader uniform variable this texture is -// bound to. -@property (nonatomic, retain) NSString * identifier; - -// The texture coordinates to use for this texture; -1 if not set because it's from an old file -@property (nonatomic, assign) int16_t texCoordSet; - -// The mesh this texture belongs to. -@property (nonatomic, retain) GLLItemMesh *mesh; - -// Description -@property (nonatomic, readonly) GLLTextureDescription *textureDescription; - -@end diff --git a/GLLara/GLLItemMeshTexture.m b/GLLara/GLLItemMeshTexture.m deleted file mode 100644 index ce57e02..0000000 --- a/GLLara/GLLItemMeshTexture.m +++ /dev/null @@ -1,61 +0,0 @@ -// -// GLLItemMeshTexture.m -// GLLara -// -// Created by Torsten Kammer on 03.02.13. -// Copyright (c) 2013 Torsten Kammer. All rights reserved. -// - -#import "GLLItemMeshTexture.h" - -#import "GLLItemMesh.h" - -#import "GLLara-Swift.h" - -@implementation GLLItemMeshTexture - -@dynamic textureURL; -@dynamic textureBookmarkData; -@dynamic identifier; -@dynamic texCoordSet; -@dynamic mesh; - -- (void)awakeFromFetch -{ - [super awakeFromFetch]; - - // Get URL from bookmark - NSData *bookmarkData = self.textureBookmarkData; - if (bookmarkData) - { - NSURL *textureURL = [NSURL URLByResolvingBookmarkData:bookmarkData options:0 relativeToURL:nil bookmarkDataIsStale:NULL error:NULL]; - [self setPrimitiveValue:textureURL forKey:@"textureURL"]; - } -} - -- (void)willSave -{ - // Put URL into bookmark - NSURL *textureURL = [self primitiveValueForKey:@"textureURL"]; - if (textureURL) - { - NSData *bookmark = [textureURL bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL]; - [self setPrimitiveValue:bookmark forKey:@"textureBookmarkData"]; - } - else - [self setPrimitiveValue:nil forKey:@"textureBookmarkData"]; -} - -- (void)setTexCoordSet:(int16_t)texCoordSet { - [self willChangeValueForKey:@"texCoordSet"]; - [self setPrimitiveValue:@(texCoordSet) forKey:@"texCoordSet"]; - [self.mesh updateShader]; - [self didChangeValueForKey:@"texCoordSet"]; -} - -- (GLLTextureDescription *)textureDescription -{ - return [self.mesh.mesh.shader descriptionForTexture:self.identifier]; -} - -@end diff --git a/GLLara/GLLItemMeshTexture.swift b/GLLara/GLLItemMeshTexture.swift new file mode 100644 index 0000000..b12acf5 --- /dev/null +++ b/GLLara/GLLItemMeshTexture.swift @@ -0,0 +1,68 @@ +// +// GLLItemMeshTexture+CoreDataClass.swift +// GLLara +// +// Created by Torsten Kammer on 03.05.24. +// Copyright © 2024 Torsten Kammer. All rights reserved. +// +// + +import Foundation +import CoreData + +@objc(GLLItemMeshTexture) +public class GLLItemMeshTexture: NSManagedObject { + + // Get URL from bookmark + @objc public override func awakeFromFetch() { + if let data = textureBookmarkData { + var stale = false + if let textureUrl = try? URL(resolvingBookmarkData: data, options: [], relativeTo: nil, bookmarkDataIsStale: &stale) { + self.setPrimitiveValue(textureUrl, forKey: "textureURL") + } + } + } + + @objc public override func willSave() { + // Put URL into bookmark + if let url = self.primitiveValue(forKey: "textureURL") as? NSURL { + let textureUrl = url as URL + if let bookmark = try? textureUrl.bookmarkData() { + self.setPrimitiveValue(bookmark, forKey: "textureBookmarkData") + } + } else { + self.setPrimitiveValue(nil, forKey: "textureBookmarkData") + } + } + + @objc var texCoordSet: Int { + set { + willChangeValue(for: \.texCoordSet) + setPrimitiveValue(NSNumber(value: newValue), forKey: "texCoordSet") + mesh?.updateShader() + didChangeValue(for: \.texCoordSet) + } + get { + return (primitiveValue(forKey: "texCoordSet") as! NSNumber).intValue + } + } + + @objc var textureDescription: GLLTextureDescription? { + guard let identifier, let mesh, let shader = mesh.mesh.shader else { + return nil + } + return shader.description(forTexture: identifier) + } +} + +extension GLLItemMeshTexture { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "GLLItemMeshTexture") + } + + @NSManaged public var identifier: String? + @NSManaged public var textureBookmarkData: Data? + @NSManaged public var textureURL: NSURL? + @NSManaged public var mesh: GLLItemMesh? +} diff --git a/GLLara/GLLItemMeshTextureSelectionPlaceholder.m b/GLLara/GLLItemMeshTextureSelectionPlaceholder.m index 29dc7af..aea4a4a 100644 --- a/GLLara/GLLItemMeshTextureSelectionPlaceholder.m +++ b/GLLara/GLLItemMeshTextureSelectionPlaceholder.m @@ -9,7 +9,7 @@ #import "GLLItemMeshTextureSelectionPlaceholder.h" #import "GLLItemMesh.h" -#import "GLLItemMeshTexture.h" +#import "GLLara-Swift.h" @interface GLLItemMeshTextureSelectionPlaceholder () diff --git a/GLLara/GLLItemViewController.m b/GLLara/GLLItemViewController.m index fd635fa..4204501 100644 --- a/GLLara/GLLItemViewController.m +++ b/GLLara/GLLItemViewController.m @@ -12,7 +12,6 @@ #import "GLLItem.h" #import "GLLItemMesh.h" -#import "GLLItemMeshTexture.h" #import "GLLara-Swift.h" @interface GLLItemViewController () diff --git a/GLLara/GLLMeshViewController.m b/GLLara/GLLMeshViewController.m index 4ce54ee..331d3c8 100644 --- a/GLLara/GLLMeshViewController.m +++ b/GLLara/GLLMeshViewController.m @@ -10,7 +10,6 @@ #import "GLLItemMesh.h" #import "GLLItemMeshSelectionPlaceholder.h" -#import "GLLItemMeshTexture.h" #import "GLLItemMeshTextureSelectionPlaceholder.h" #import "GLLRenderParameter.h" #import "GLLRenderParameterSelectionPlaceholder.h" diff --git a/GLLara/GLLara-Bridging-Header.h b/GLLara/GLLara-Bridging-Header.h index 4819369..d1cee43 100644 --- a/GLLara/GLLara-Bridging-Header.h +++ b/GLLara/GLLara-Bridging-Header.h @@ -15,7 +15,6 @@ #import "GLLItem.h" #import "GLLItemBone.h" #import "GLLItemMesh.h" -#import "GLLItemMeshTexture.h" #import "GLLNotifications.h" #import "GLLVertexAttrib.h" #import "GLLPreferencesWindowController.h"