-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not sure this code really works
- Loading branch information
Showing
5 changed files
with
59 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |