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

Function obj2gltf

lib/obj2gltf.js:46–141  ·  view source on GitHub ↗

* Converts an obj file to a glTF or glb. * * @param {String} objPath Path to the obj file. * @param {Object} [options] An object with the following properties: * @param {Boolean} [options.binary=false] Convert to binary glTF. * @param {Boolean} [options.separate=false] Write out separate buffer

(objPath, options)

Source from the content-addressed store, hash-verified

44 * @return {Promise} A promise that resolves to the glTF JSON or glb buffer.
45 */
46function obj2gltf(objPath, options) {
47 const defaults = obj2gltf.defaults;
48 options = defaultValue(options, {});
49 options.binary = defaultValue(options.binary, defaults.binary);
50 options.separate = defaultValue(options.separate, defaults.separate);
51 options.separateTextures =
52 defaultValue(options.separateTextures, defaults.separateTextures) ||
53 options.separate;
54 options.checkTransparency = defaultValue(
55 options.checkTransparency,
56 defaults.checkTransparency,
57 );
58 options.doubleSidedMaterial = defaultValue(
59 options.doubleSidedMaterial,
60 defaults.doubleSidedMaterial,
61 );
62 options.secure = defaultValue(options.secure, defaults.secure);
63 options.packOcclusion = defaultValue(
64 options.packOcclusion,
65 defaults.packOcclusion,
66 );
67 options.metallicRoughness = defaultValue(
68 options.metallicRoughness,
69 defaults.metallicRoughness,
70 );
71 options.specularGlossiness = defaultValue(
72 options.specularGlossiness,
73 defaults.specularGlossiness,
74 );
75 options.unlit = defaultValue(options.unlit, defaults.unlit);
76 options.overridingTextures = defaultValue(
77 options.overridingTextures,
78 Cesium.Frozen.EMPTY_OBJECT,
79 );
80 options.logger = defaultValue(options.logger, getDefaultLogger());
81 options.writer = defaultValue(
82 options.writer,
83 getDefaultWriter(options.outputDirectory),
84 );
85 options.inputUpAxis = defaultValue(options.inputUpAxis, defaults.inputUpAxis);
86 options.outputUpAxis = defaultValue(
87 options.outputUpAxis,
88 defaults.outputUpAxis,
89 );
90 options.triangleWindingOrderSanitization = defaultValue(
91 options.triangleWindingOrderSanitization,
92 defaults.triangleWindingOrderSanitization,
93 );
94
95 if (!defined(objPath)) {
96 throw new DeveloperError("objPath is required");
97 }
98
99 if (options.separateTextures && !defined(options.writer)) {
100 throw new DeveloperError(
101 "Either options.writer or options.outputDirectory must be defined when writing separate resources.",
102 );
103 }

Callers 2

obj2gltfSpec.jsFile · 0.85
obj2gltf.jsFile · 0.85

Calls 6

getDefaultLoggerFunction · 0.85
getDefaultWriterFunction · 0.85
loadObjFunction · 0.85
createGltfFunction · 0.85
writeGltfFunction · 0.85
defaultValueFunction · 0.70

Tested by

no test coverage detected