-
Notifications
You must be signed in to change notification settings - Fork 6
/
GLLModelMeshObj.swift
46 lines (36 loc) · 2 KB
/
GLLModelMeshObj.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// GLLModelMeshObj.swift
// GLLara
//
// Created by Torsten Kammer on 06.04.22.
// Copyright © 2022 Torsten Kammer. All rights reserved.
//
import Foundation
class GLLModelMeshObj: GLLModelMesh {
init(asPartOfModel model: GLLModel, fileVertexAccessors: GLLVertexAttribAccessorSet, countOfVertices: Int, elementData: Data, textures: [String: GLLTextureAssignment], renderParameterValues: [String: AnyObject]) throws {
super.init(asPartOfModel: model)
countOfUVLayers = 1
self.countOfVertices = countOfVertices
let tangents = calculateTangents(for: fileVertexAccessors)
vertexDataAccessors = fileVertexAccessors.combining(with: tangents)
self.elementData = elementData
self.countOfElements = elementData.count / 4
// Previous actions may have disturbed vertex format (because it also depends on count of vertices) so uncache it.
vertexFormat = vertexDataAccessors!.vertexFormat(vertexCount: countOfVertices, hasIndices: true)
// Setup material
// Three options: Diffuse, DiffuseSpecular, DiffuseNormal, DiffuseSpecularNormal
self.textures = textures
self.renderParameterValues = renderParameterValues
let objModelParams = try GLLModelParams.parameters(forName: "objFileParameters")
shader = objModelParams.shader(base: "default", modules: [], presentTextures: Array(textures.keys), vertexAccessors: vertexDataAccessors!, alphaBlending: true)
// Always use blending, since I can't prove that it doesn't otherwise.
usesAlphaBlending = true
}
override var hasBoneWeights: Bool {
return false // OBJ files don't use them. They do use one bone matrix, for the model position, but that's it.
}
override var colorsAreFloats: Bool {
// OBJ files that have colors store them as floats, and since they make use of features (e.g. values outside [0;1]) it's better to keep them that way.
return true
}
}