Skip to content

Commit

Permalink
More Swift
Browse files Browse the repository at this point in the history
Not sure this code really works
  • Loading branch information
cochrane committed May 3, 2024
1 parent 77630aa commit e43bae4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 94 deletions.
10 changes: 4 additions & 6 deletions GLLara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
5267F1B61615B2C400987717 /* moveChildren.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 5267F1B31615B2C400987717 /* moveChildren.pdf */; };
5267F1B71615B2C400987717 /* moveNodeOnly.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 5267F1B41615B2C400987717 /* moveNodeOnly.pdf */; };
5267F1B81615B2C400987717 /* moveParent.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 5267F1B51615B2C400987717 /* moveParent.pdf */; };
526AB3151609BD4300940A74 /* GLLItemMesh+OBJExport.m in Sources */ = {isa = PBXBuildFile; fileRef = 526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.m */; };
526AB3151609BD4300940A74 /* GLLItemMesh+OBJExport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.swift */; };
526AB31C1609C7C300940A74 /* GLLItem+OBJExport.m in Sources */ = {isa = PBXBuildFile; fileRef = 526AB31B1609C7C300940A74 /* GLLItem+OBJExport.m */; };
526D5AE62060596000DCDE85 /* GLLNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 526D5AE52060596000DCDE85 /* GLLNotifications.m */; };
526E0F9C1C169E3500F198BF /* testDiffuse.png in Resources */ = {isa = PBXBuildFile; fileRef = 526E0F8B1C169E3500F198BF /* testDiffuse.png */; };
Expand Down Expand Up @@ -646,8 +646,7 @@
5267F1B31615B2C400987717 /* moveChildren.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = moveChildren.pdf; sourceTree = "<group>"; };
5267F1B41615B2C400987717 /* moveNodeOnly.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = moveNodeOnly.pdf; sourceTree = "<group>"; };
5267F1B51615B2C400987717 /* moveParent.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = moveParent.pdf; sourceTree = "<group>"; };
526AB3131609BD4300940A74 /* GLLItemMesh+OBJExport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GLLItemMesh+OBJExport.h"; sourceTree = "<group>"; };
526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GLLItemMesh+OBJExport.m"; sourceTree = "<group>"; };
526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GLLItemMesh+OBJExport.swift"; sourceTree = "<group>"; };
526AB31A1609C7C300940A74 /* GLLItem+OBJExport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GLLItem+OBJExport.h"; sourceTree = "<group>"; };
526AB31B1609C7C300940A74 /* GLLItem+OBJExport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GLLItem+OBJExport.m"; sourceTree = "<group>"; };
526D5AE52060596000DCDE85 /* GLLNotifications.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLLNotifications.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1369,8 +1368,7 @@
52C9F6221600CCFC003272E1 /* GLLColorRenderParameter.m */,
52BB21D915FCF02200937450 /* GLLCamera.h */,
52BB21DA15FCF02200937450 /* GLLCamera.m */,
526AB3131609BD4300940A74 /* GLLItemMesh+OBJExport.h */,
526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.m */,
526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.swift */,
526AB31A1609C7C300940A74 /* GLLItem+OBJExport.h */,
526AB31B1609C7C300940A74 /* GLLItem+OBJExport.m */,
5214470916DBF206003E260F /* GLLItemMesh+MeshExport.swift */,
Expand Down Expand Up @@ -1917,7 +1915,7 @@
5275F6821607293000978779 /* GLLItemController.m in Sources */,
52C516FF2871998C000EB8C2 /* GLLPipelineStateInformation.swift in Sources */,
5275F6891607399800978779 /* GLLItemListController.m in Sources */,
526AB3151609BD4300940A74 /* GLLItemMesh+OBJExport.m in Sources */,
526AB3151609BD4300940A74 /* GLLItemMesh+OBJExport.swift in Sources */,
52B6C5392BE2EB26005E53CE /* MtlFile.swift in Sources */,
526AB31C1609C7C300940A74 /* GLLItem+OBJExport.m in Sources */,
525BF29D287A0AE200E30D48 /* GLLView.swift in Sources */,
Expand Down
1 change: 0 additions & 1 deletion GLLara/GLLItem+OBJExport.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#import "NSArray+Map.h"
#import "GLLItemBone.h"
#import "GLLItemMesh+OBJExport.h"

#import "GLLara-Swift.h"

Expand Down
22 changes: 0 additions & 22 deletions GLLara/GLLItemMesh+OBJExport.h

This file was deleted.

65 changes: 0 additions & 65 deletions GLLara/GLLItemMesh+OBJExport.m

This file was deleted.

55 changes: 55 additions & 0 deletions GLLara/GLLItemMesh+OBJExport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// GLLItemMesh+OBJExport.m
// GLLara
//
// Created by Torsten Kammer on 19.09.12.
// Copyright (c) 2012 Torsten Kammer. All rights reserved.
//

import Foundation

extension GLLItemMesh {

@objc var willLoseDataWhenConvertedToOBJ: Bool {
return (self.mesh.textures.count > 1) || (self.mesh.textures.count == 1 && self.mesh.textures["diffuseTexture"]?.url == nil) || (self.renderParameters.count > 0)
}

@objc func writeMTL(baseURL: URL) -> String {
var result = "newmtl material\(meshIndex)\n"

// Use only first texture and only if it isn't baked into the model file
// TODO It's probably possible to extract this texture, but does anyone care?
if let url = mesh.textures["diffuseTexture"]?.url {
let baseComponents = baseURL.pathComponents
let textureComponents = url.pathComponents

// Find where the paths diverge
var commonPathLength = 0
for i in 0 ..< min(baseComponents.count, textureComponents.count) {
if baseComponents[i] != textureComponents[i] {
break
} else {
commonPathLength = i
}
}

var relativePathComponents: [String] = []

// Add .. for any additional path in the base file
for _ in commonPathLength ..< baseComponents.count - 1 {
relativePathComponents.append("..")
}

relativePathComponents.append(contentsOf: textureComponents.dropFirst(commonPathLength))

let relativePath = relativePathComponents.joined(separator: "/")
result += "map_Kd \(relativePath)\r\n"
}
return result
}

@objc func writeOBJ(transformations: UnsafePointer<mat_float16>, baseIndex: Int, includeColors: Bool) -> String {
return mesh.writeOBJ(transformations: transformations, baseIndex: baseIndex, includeColors: includeColors)
}

}

0 comments on commit e43bae4

Please sign in to comment.