From b937f118ab0951b4c2be243f8277e327ad56f2d7 Mon Sep 17 00:00:00 2001 From: Torsten Kammer Date: Wed, 28 Jul 2021 10:06:13 +0200 Subject: [PATCH] New version 0.2.12 Adds support for XPS v3 files. --- GLLara.xcodeproj/project.pbxproj | 14 ++++++++++---- GLLara/GLLModel.m | 20 ++++++++++++++------ GLLara/GLLModelMesh.h | 1 + GLLara/GLLModelMesh.m | 8 ++++++++ GLLara/GLLModelMeshV4.swift | 17 +++++++++++++++++ GLLara/GLLVertexArray.m | 10 ++++++++-- GLLara/GLLVertexAttrib.h | 1 + GLLara/GLLara-Bridging-Header.h | 1 + 8 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 GLLara/GLLModelMeshV4.swift diff --git a/GLLara.xcodeproj/project.pbxproj b/GLLara.xcodeproj/project.pbxproj index 57b9e5f..a44e73c 100644 --- a/GLLara.xcodeproj/project.pbxproj +++ b/GLLara.xcodeproj/project.pbxproj @@ -334,6 +334,8 @@ 52D8DDF72621E67F0006F0E5 /* GLLShaderDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52D8DDF12621E19A0006F0E5 /* GLLShaderDescription.swift */; }; 52D8DE022621F5910006F0E5 /* GLLModelParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52D8DDFC2621F29D0006F0E5 /* GLLModelParams.swift */; }; 52DD80F3163B464200534475 /* GLLRenderingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 52DD80F2163B464200534475 /* GLLRenderingTest.m */; }; + 52E864B926B144120005AA82 /* (null) in Sources */ = {isa = PBXBuildFile; }; + 52E864BB26B147180005AA82 /* GLLModelMeshV4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52E864BA26B147180005AA82 /* GLLModelMeshV4.swift */; }; 52ED9E1E168399AE0082EABB /* GLLSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 52ED9E1D168399AE0082EABB /* GLLSelection.m */; }; 52ED9E26169332540082EABB /* GLLMeshController.m in Sources */ = {isa = PBXBuildFile; fileRef = 52ED9E25169332540082EABB /* GLLMeshController.m */; }; 52ED9E29169333050082EABB /* GLLBoneController.m in Sources */ = {isa = PBXBuildFile; fileRef = 52ED9E28169333050082EABB /* GLLBoneController.m */; }; @@ -882,6 +884,7 @@ 52DD80F7163B58E400534475 /* GLLExportASCIITest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLExportASCIITest.m; sourceTree = ""; }; 52DD80F9163B58F100534475 /* GLLExportBinaryTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLExportBinaryTest.h; sourceTree = ""; }; 52DD80FA163B58F100534475 /* GLLExportBinaryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLExportBinaryTest.m; sourceTree = ""; }; + 52E864BA26B147180005AA82 /* GLLModelMeshV4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GLLModelMeshV4.swift; sourceTree = ""; }; 52ED9E1C168399AE0082EABB /* GLLSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLSelection.h; sourceTree = ""; }; 52ED9E1D168399AE0082EABB /* GLLSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLSelection.m; sourceTree = ""; }; 52ED9E24169332540082EABB /* GLLMeshController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLMeshController.h; sourceTree = ""; }; @@ -1397,6 +1400,7 @@ 5296941E15F4111A00DF2FA3 /* Model Resources */ = { isa = PBXGroup; children = ( + 52E864BA26B147180005AA82 /* GLLModelMeshV4.swift */, 52D8DDDD2621CFF10006F0E5 /* GLLMeshSplitter.swift */, 525ACD8215F0F33700534E7D /* GLLModel.h */, 525ACD8315F0F33700534E7D /* GLLModel.m */, @@ -1992,6 +1996,7 @@ 529693F515F2B58B00DF2FA3 /* GLLASCIIScanner.m in Sources */, 5296940115F3881B00DF2FA3 /* GLLModelProgram.m in Sources */, 5296940415F3893200DF2FA3 /* GLLShader.m in Sources */, + 52E864BB26B147180005AA82 /* GLLModelMeshV4.swift in Sources */, 5296942415F411CC00DF2FA3 /* GLLModelDrawData.m in Sources */, 5296942815F4139300DF2FA3 /* GLLItemDrawer.m in Sources */, 5296942B15F4174F00DF2FA3 /* GLLSceneDrawer.m in Sources */, @@ -2054,6 +2059,7 @@ 528934E816A29B8300F05312 /* GLLLightController.m in Sources */, 52301E382089372200B3E331 /* GLLOptionalPart.m in Sources */, 52D8DDE62621D47E0006F0E5 /* GLLTextureDescription.swift in Sources */, + 52E864B926B144120005AA82 /* (null) in Sources */, 52D8DE022621F5910006F0E5 /* GLLModelParams.swift in Sources */, 528934EB16A332BD00F05312 /* GLLMeshListController.m in Sources */, 528934EE16A3593500F05312 /* GLLBoneListController.m in Sources */, @@ -2576,13 +2582,13 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 16; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = MXAKMKWG34; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "GLLara/GLLara-Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 0.2.11; + MARKETING_VERSION = 0.2.12; PRODUCT_BUNDLE_IDENTIFIER = "de.ferroequinologist.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; @@ -2601,13 +2607,13 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 16; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = MXAKMKWG34; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "GLLara/GLLara-Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 0.2.11; + MARKETING_VERSION = 0.2.12; PRODUCT_BUNDLE_IDENTIFIER = "de.ferroequinologist.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; diff --git a/GLLara/GLLModel.m b/GLLara/GLLModel.m index c34b4a9..c8a7303 100644 --- a/GLLara/GLLModel.m +++ b/GLLara/GLLModel.m @@ -132,8 +132,7 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode TRInDataStream *stream = [[TRInDataStream alloc] initWithData:data]; - BOOL isGenericItem2 = NO; - BOOL isGenericItem3 = NO; + NSUInteger genericItemVersion = 0; NSUInteger header = [stream readUint32]; if (header == 323232) @@ -145,7 +144,7 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode * it in any way. */ NSLog(@"Warning: Using experimental, hackish, ugly Generic Item 2 support"); - isGenericItem2 = YES; + genericItemVersion = 2; // First: Two uint16s. My guess: Major, then minor version. // Always 1 and 12. @@ -164,7 +163,7 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode } else if (possiblyMajorVersion == 0x0002) { - isGenericItem3 = YES; + genericItemVersion = 3; if (possiblyMinorVersion != 0x0000F && possiblyMinorVersion != 0x000E) { if (error) @@ -174,6 +173,10 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode return nil; } } + else if (possiblyMajorVersion == 0x0003) + { + genericItemVersion = 4; + } else { if (error) @@ -237,7 +240,12 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode NSUInteger numMeshes = [stream readUint32]; NSMutableArray *meshes = [[NSMutableArray alloc] initWithCapacity:numMeshes]; - Class meshClass = isGenericItem3 ? [GLLModelMeshV3 class] : [GLLModelMesh class]; + Class meshClass = [GLLModelMesh class]; + if (genericItemVersion >= 4) { + meshClass = [GLLModelMeshV4 class]; + } else if (genericItemVersion >= 3) { + meshClass = [GLLModelMeshV3 class]; + } for (NSUInteger i = 0; i < numMeshes; i++) { GLLModelMesh *mesh = [[meshClass alloc] initFromStream:stream partOfModel:self error:error]; @@ -256,7 +264,7 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode return nil; } - if (isGenericItem2 && !stream.isAtEnd) + if ((genericItemVersion >= 2) && !stream.isAtEnd) { // A string; always $$XNAaraL$$ NSString *footerAuthor = [stream readPascalString]; diff --git a/GLLara/GLLModelMesh.h b/GLLara/GLLModelMesh.h index 7e8a680..136c826 100644 --- a/GLLara/GLLModelMesh.h +++ b/GLLara/GLLModelMesh.h @@ -80,6 +80,7 @@ typedef enum GLLCullFaceMode @property (nonatomic, assign) NSUInteger countOfUVLayers; @property (nonatomic, assign, readonly) BOOL hasBoneWeights; @property (nonatomic, readonly) BOOL hasTangentsInFile; +@property (nonatomic, readonly) BOOL hasV4ExtraBytes; @property (nonatomic, readonly) BOOL colorsAreFloats; @property (nonatomic, copy, readonly) NSURL *baseURL; diff --git a/GLLara/GLLModelMesh.m b/GLLara/GLLModelMesh.m index 68fc53a..25f4c7f 100644 --- a/GLLara/GLLModelMesh.m +++ b/GLLara/GLLModelMesh.m @@ -315,6 +315,8 @@ - (GLLVertexFormat *)fileVertexFormat { for (NSUInteger i = 0; i < self.countOfUVLayers; i++) { [attributes addObject:[[GLLVertexAttrib alloc] initWithSemantic:GLLVertexAttribTangent0 layer:i size:GLLVertexAttribSizeVec4 componentType:GLLVertexAttribComponentTypeFloat]]; } + } else if (self.hasV4ExtraBytes) { + [attributes addObject:[[GLLVertexAttrib alloc] initWithSemantic:GLLVertexAttribPadding layer:0 size:GLLVertexAttribSizeVec2 componentType:GLLVertexAttribComponentTypeUnsignedByte]]; } if (self.hasBoneWeights) { [attributes addObject:[[GLLVertexAttrib alloc] initWithSemantic:GLLVertexAttribBoneIndices layer:0 size:GLLVertexAttribSizeVec4 componentType:GLLVertexAttribComponentTypeUnsignedShort]]; @@ -359,6 +361,12 @@ - (BOOL)hasTangentsInFile return YES; } +- (BOOL)hasV4ExtraBytes +{ + // For subclasses to override + return NO; +} + - (BOOL)colorsAreFloats { // For subclasses to override diff --git a/GLLara/GLLModelMeshV4.swift b/GLLara/GLLModelMeshV4.swift new file mode 100644 index 0000000..433ac63 --- /dev/null +++ b/GLLara/GLLModelMeshV4.swift @@ -0,0 +1,17 @@ +// +// GLLModelMeshV4.swift +// GLLara +// +// Created by Torsten Kammer on 28.07.21. +// Copyright © 2021 Torsten Kammer. All rights reserved. +// + +import Foundation + +@objc class GLLModelMeshV4: GLLModelMeshV3 { + // This format has two extra bytes between texture coords and bone weights. + // Why? Who knows. It's not like anybody documents this shit. + override var hasV4ExtraBytes: Bool { + return true + } +} diff --git a/GLLara/GLLVertexArray.m b/GLLara/GLLVertexArray.m index 41609e5..19305d2 100644 --- a/GLLara/GLLVertexArray.m +++ b/GLLara/GLLVertexArray.m @@ -106,8 +106,10 @@ - (id)initWithFormat:(GLLVertexFormat *)format; NSUInteger stride = 0; for (GLLVertexAttrib *attribute in format.attributes) { GLLVertexAttrib *optimized = [self optimizedVersionOf:attribute]; - [optimizedAttributes addObject:optimized]; - stride += optimized.sizeInBytes; + if (optimized) { + [optimizedAttributes addObject:optimized]; + stride += optimized.sizeInBytes; + } } NSUInteger offset = 0; @@ -124,6 +126,10 @@ - (id)initWithFormat:(GLLVertexFormat *)format; } - (GLLVertexAttrib *)optimizedVersionOf:(GLLVertexAttrib *)attribute { + if (attribute.semantic == GLLVertexAttribPadding) { + return nil; + } + // Change Normal (if float[3]) to vec4 with 2_10_10_10_rev encoding // (this adds a W component which gets ignored by the shader) if (attribute.semantic == GLLVertexAttribNormal && attribute.size == GLLVertexAttribSizeVec3 && attribute.type == GLLVertexAttribComponentTypeFloat) { diff --git a/GLLara/GLLVertexAttrib.h b/GLLara/GLLVertexAttrib.h index adbaaaa..47bf5cb 100644 --- a/GLLara/GLLVertexAttrib.h +++ b/GLLara/GLLVertexAttrib.h @@ -22,6 +22,7 @@ typedef NS_ENUM(NSInteger, GLLVertexAttribSemantic) GLLVertexAttribBoneWeights, GLLVertexAttribTexCoord0, GLLVertexAttribTangent0, + GLLVertexAttribPadding }; typedef NS_ENUM(NSInteger, GLLVertexAttribSize) { diff --git a/GLLara/GLLara-Bridging-Header.h b/GLLara/GLLara-Bridging-Header.h index e87edc5..32c29fb 100644 --- a/GLLara/GLLara-Bridging-Header.h +++ b/GLLara/GLLara-Bridging-Header.h @@ -5,6 +5,7 @@ #import "GLLModel.h" #import "GLLModelBone.h" #import "GLLModelMesh.h" +#import "GLLModelMeshV3.h" #import "GLLVertexAttrib.h" #import "GLLVertexAttribAccessor.h" #import "GLLVertexAttribAccessorSet.h"