Skip to content

Commit

Permalink
Simplify and remove weight
Browse files Browse the repository at this point in the history
Full OBJ export now Swift
  • Loading branch information
cochrane committed May 3, 2024
1 parent e43bae4 commit 94f4f5b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 98 deletions.
10 changes: 4 additions & 6 deletions GLLara.xcodeproj/project.pbxproj
Expand Up @@ -209,7 +209,7 @@
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.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.swift */; };
526AB31C1609C7C300940A74 /* GLLItem+OBJExport.m in Sources */ = {isa = PBXBuildFile; fileRef = 526AB31B1609C7C300940A74 /* GLLItem+OBJExport.m */; };
526AB31C1609C7C300940A74 /* GLLItem+OBJExport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526AB31B1609C7C300940A74 /* GLLItem+OBJExport.swift */; };
526D5AE62060596000DCDE85 /* GLLNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 526D5AE52060596000DCDE85 /* GLLNotifications.m */; };
526E0F9C1C169E3500F198BF /* testDiffuse.png in Resources */ = {isa = PBXBuildFile; fileRef = 526E0F8B1C169E3500F198BF /* testDiffuse.png */; };
526E0F9D1C169E3500F198BF /* testDiffuseBump.png in Resources */ = {isa = PBXBuildFile; fileRef = 526E0F8C1C169E3500F198BF /* testDiffuseBump.png */; };
Expand Down Expand Up @@ -647,8 +647,7 @@
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>"; };
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>"; };
526AB31B1609C7C300940A74 /* GLLItem+OBJExport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GLLItem+OBJExport.swift"; sourceTree = "<group>"; };
526D5AE52060596000DCDE85 /* GLLNotifications.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLLNotifications.m; sourceTree = "<group>"; };
526D5AE72060596E00DCDE85 /* GLLNotifications.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLLNotifications.h; sourceTree = "<group>"; };
526E0F891C146B8000F198BF /* GLLSceneModel 4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "GLLSceneModel 4.xcdatamodel"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1369,8 +1368,7 @@
52BB21D915FCF02200937450 /* GLLCamera.h */,
52BB21DA15FCF02200937450 /* GLLCamera.m */,
526AB3141609BD4300940A74 /* GLLItemMesh+OBJExport.swift */,
526AB31A1609C7C300940A74 /* GLLItem+OBJExport.h */,
526AB31B1609C7C300940A74 /* GLLItem+OBJExport.m */,
526AB31B1609C7C300940A74 /* GLLItem+OBJExport.swift */,
5214470916DBF206003E260F /* GLLItemMesh+MeshExport.swift */,
5214470C16DC2312003E260F /* GLLItem+MeshExport.swift */,
521102EE2899C430001BE4BC /* GLLItemBoneExtensions.swift */,
Expand Down Expand Up @@ -1917,7 +1915,7 @@
5275F6891607399800978779 /* GLLItemListController.m in Sources */,
526AB3151609BD4300940A74 /* GLLItemMesh+OBJExport.swift in Sources */,
52B6C5392BE2EB26005E53CE /* MtlFile.swift in Sources */,
526AB31C1609C7C300940A74 /* GLLItem+OBJExport.m in Sources */,
526AB31C1609C7C300940A74 /* GLLItem+OBJExport.swift in Sources */,
525BF29D287A0AE200E30D48 /* GLLView.swift in Sources */,
52CDFEE42875B46700BC4298 /* GLLSceneDrawer.swift in Sources */,
52301E352087E71400B3E331 /* GLLOptionalPartViewController.m in Sources */,
Expand Down
5 changes: 2 additions & 3 deletions GLLara/GLLDocument.m
Expand Up @@ -18,7 +18,6 @@
#import "GLLItem.h"
#import "GLLItemBone.h"
#import "GLLItemMesh.h"
#import "GLLItem+OBJExport.h"
#import "GLLLogarithmicValueTransformer.h"
#import "GLLRenderWindowController.h"
#import "GLLSelection.h"
Expand Down Expand Up @@ -304,12 +303,12 @@ - (IBAction)exportSelectedModel:(id)sender
NSURL *mtlURL = [NSURL URLWithString:materialLibraryName relativeToURL:objURL];

NSError *error = nil;
if (![item writeOBJToLocation:objURL withTransform:controller.includeTransformations withColor:controller.includeVertexColors error:&error])
if (![item writeOBJWithLocation:objURL transform:controller.includeTransformations color:controller.includeVertexColors error:&error])
{
[self.windowForSheet presentError:error];
return;
}
if (![item writeMTLToLocation:mtlURL error:&error])
if (![item writeMTLWithLocation:mtlURL error:&error])
{
[self.windowForSheet presentError:error];
return;
Expand Down
1 change: 0 additions & 1 deletion GLLara/GLLDocumentWindowController.m
Expand Up @@ -16,7 +16,6 @@
#import "GLLDirectionalLight.h"
#import "GLLDocument.h"
#import "GLLItem.h"
#import "GLLItem+OBJExport.h"
#import "GLLItemBone.h"
#import "GLLItemController.h"
#import "GLLItemListController.h"
Expand Down
20 changes: 0 additions & 20 deletions GLLara/GLLItem+OBJExport.h

This file was deleted.

63 changes: 0 additions & 63 deletions GLLara/GLLItem+OBJExport.m

This file was deleted.

45 changes: 45 additions & 0 deletions GLLara/GLLItem+OBJExport.swift
@@ -0,0 +1,45 @@
//
// GLLItem+OBJExport.m
// GLLara
//
// Created by Torsten Kammer on 19.09.12.
// Copyright (c) 2012 Torsten Kammer. All rights reserved.
//

import Foundation

extension GLLItem {
@objc var willLoseDataWhenConvertedToOBJ: Bool {
return meshes.first { ($0 as! GLLItemMesh).willLoseDataWhenConvertedToOBJ } != nil
}

@objc func writeOBJ(location: URL, transform: Bool, color: Bool) throws {
var string = ""

let materialLibraryName = location.deletingPathExtension().appendingPathExtension(".mtl").lastPathComponent
string += "usemtl \(materialLibraryName)\r\n"

var transforms = Array<mat_float16>(repeating: mat_float16(), count: bones.count)
var boneIndex = 0
for bone in bones {
if transform {
transforms[boneIndex] = (bone as! GLLItemBone).globalTransform
} else {
transforms[boneIndex] = (bone as! GLLItemBone).bone.positionMatrix
}
boneIndex += 1
}

var indexOffset = 0
for mesh in meshes {
string += (mesh as! GLLItemMesh).writeOBJ(transformations: transforms, baseIndex: indexOffset, includeColors: color)
indexOffset += (mesh as! GLLItemMesh).mesh.countOfVertices
}
try string.write(to: location, atomically: true, encoding: .utf8)
}

@objc func writeMTL(location: URL) throws {
let content = meshes.map { ($0 as! GLLItemMesh).writeMTL(baseURL: location) }.joined(separator: "\r\n")
try content.write(to: location, atomically: true, encoding: .utf8)
}
}
8 changes: 4 additions & 4 deletions GLLara/GLLItemMesh+OBJExport.swift
Expand Up @@ -10,12 +10,12 @@ import Foundation

extension GLLItemMesh {

@objc var willLoseDataWhenConvertedToOBJ: Bool {
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"
func writeMTL(baseURL: URL) -> String {
var result = "newmtl material\(meshIndex)\r\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?
Expand Down Expand Up @@ -48,7 +48,7 @@ extension GLLItemMesh {
return result
}

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

Expand Down
2 changes: 1 addition & 1 deletion GLLara/GLLModelMesh+OBJExport.swift
Expand Up @@ -10,7 +10,7 @@ import Foundation

extension GLLModelMesh {

@objc func writeOBJ(transformations: UnsafePointer<mat_float16>, baseIndex: Int, includeColors: Bool) -> String {
func writeOBJ(transformations: [mat_float16], baseIndex: Int, includeColors: Bool) -> String {

var objString = ""
let groupName = name.components(separatedBy: CharacterSet.whitespacesAndNewlines).joined(separator: "_")
Expand Down

0 comments on commit 94f4f5b

Please sign in to comment.