Skip to content

Commit

Permalink
New version 0.2.12
Browse files Browse the repository at this point in the history
Adds support for XPS v3 files.
  • Loading branch information
cochrane committed Jul 28, 2021
1 parent 34a89cb commit b937f11
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
14 changes: 10 additions & 4 deletions GLLara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -882,6 +884,7 @@
52DD80F7163B58E400534475 /* GLLExportASCIITest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLExportASCIITest.m; sourceTree = "<group>"; };
52DD80F9163B58F100534475 /* GLLExportBinaryTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLExportBinaryTest.h; sourceTree = "<group>"; };
52DD80FA163B58F100534475 /* GLLExportBinaryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLExportBinaryTest.m; sourceTree = "<group>"; };
52E864BA26B147180005AA82 /* GLLModelMeshV4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GLLModelMeshV4.swift; sourceTree = "<group>"; };
52ED9E1C168399AE0082EABB /* GLLSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLSelection.h; sourceTree = "<group>"; };
52ED9E1D168399AE0082EABB /* GLLSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLSelection.m; sourceTree = "<group>"; };
52ED9E24169332540082EABB /* GLLMeshController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLMeshController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1397,6 +1400,7 @@
5296941E15F4111A00DF2FA3 /* Model Resources */ = {
isa = PBXGroup;
children = (
52E864BA26B147180005AA82 /* GLLModelMeshV4.swift */,
52D8DDDD2621CFF10006F0E5 /* GLLMeshSplitter.swift */,
525ACD8215F0F33700534E7D /* GLLModel.h */,
525ACD8315F0F33700534E7D /* GLLModel.m */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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 = "";
Expand Down
20 changes: 14 additions & 6 deletions GLLara/GLLModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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)
Expand All @@ -174,6 +173,10 @@ - (id)initBinaryFromData:(NSData *)data baseURL:(NSURL *)baseURL parent:(GLLMode
return nil;
}
}
else if (possiblyMajorVersion == 0x0003)
{
genericItemVersion = 4;
}
else
{
if (error)
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions GLLara/GLLModelMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions GLLara/GLLModelMesh.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down Expand Up @@ -359,6 +361,12 @@ - (BOOL)hasTangentsInFile
return YES;
}

- (BOOL)hasV4ExtraBytes
{
// For subclasses to override
return NO;
}

- (BOOL)colorsAreFloats
{
// For subclasses to override
Expand Down
17 changes: 17 additions & 0 deletions GLLara/GLLModelMeshV4.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
10 changes: 8 additions & 2 deletions GLLara/GLLVertexArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions GLLara/GLLVertexAttrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef NS_ENUM(NSInteger, GLLVertexAttribSemantic)
GLLVertexAttribBoneWeights,
GLLVertexAttribTexCoord0,
GLLVertexAttribTangent0,
GLLVertexAttribPadding
};

typedef NS_ENUM(NSInteger, GLLVertexAttribSize) {
Expand Down
1 change: 1 addition & 0 deletions GLLara/GLLara-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b937f11

Please sign in to comment.