MCPcopy
hub / github.com/CesiumGS/obj2gltf / loadObj

Function loadObj

lib/loadObj.js:65–517  ·  view source on GitHub ↗

* Parse an obj file. * * @param {String} objPath Path to the obj file. * @param {Object} options The options object passed along from lib/obj2gltf.js * @returns {Promise} A promise resolving to the obj data, which includes an array of nodes containing geometry information and an array of materia

(objPath, options)

Source from the content-addressed store, hash-verified

63 * @private
64 */
65function loadObj(objPath, options) {
66 const axisTransform = getAxisTransform(
67 options.inputUpAxis,
68 options.outputUpAxis,
69 );
70
71 // Global store of vertex attributes listed in the obj file
72 let globalPositions = new ArrayStorage(ComponentDatatype.FLOAT);
73 let globalNormals = new ArrayStorage(ComponentDatatype.FLOAT);
74 let globalUvs = new ArrayStorage(ComponentDatatype.FLOAT);
75
76 // The current node, mesh, and primitive
77 let node;
78 let mesh;
79 let primitive;
80 let activeMaterial;
81
82 // All nodes seen in the obj
83 const nodes = [];
84
85 // Used to build the indices. The vertex cache is unique to each primitive.
86 let vertexCache = {};
87 const vertexCacheLimit = 1000000;
88 let vertexCacheCount = 0;
89 let vertexCount = 0;
90
91 // All mtl paths seen in the obj
92 let mtlPaths = [];
93
94 // Buffers for face data that spans multiple lines
95 let lineBuffer = "";
96
97 // Used for parsing face data
98 const faceVertices = [];
99 const facePositions = [];
100 const faceUvs = [];
101 const faceNormals = [];
102
103 function clearVertexCache() {
104 vertexCache = {};
105 vertexCacheCount = 0;
106 }
107
108 function getName(name) {
109 return name === "" ? undefined : name;
110 }
111
112 function addNode(name) {
113 node = new Node();
114 node.name = getName(name);
115 nodes.push(node);
116 addMesh();
117 }
118
119 function addMesh(name) {
120 mesh = new Mesh();
121 mesh.name = getName(name);
122 node.meshes.push(mesh);

Callers 5

obj2gltfFunction · 0.85
createGltfSpec.jsFile · 0.85
loadObjSpec.jsFile · 0.85
checkAxisConversionFunction · 0.85
loadAndGetIndicesFunction · 0.85

Calls 4

getAxisTransformFunction · 0.85
readLinesFunction · 0.85
finishLoadingFunction · 0.85
addNodeFunction · 0.70

Tested by

no test coverage detected