Giter Site home page Giter Site logo

obj2gltf's Introduction

OBJ2GLTF

Convert OBJ assets to glTF 2.0.

Getting Started

Install Node.js if you don't already have it, and then:

npm install -g obj2gltf

Using obj2gltf as a command-line tool:

obj2gltf -i model.obj

obj2gltf -i model.obj -o model.gltf

obj2gltf -i model.obj -o model.glb

Using obj2gltf as a library:

Converting an obj model to gltf:

const obj2gltf = require("obj2gltf");
const fs = require("fs");
obj2gltf("model.obj").then(function (gltf) {
  const data = Buffer.from(JSON.stringify(gltf));
  fs.writeFileSync("model.gltf", data);
});

Converting an obj model to glb

const obj2gltf = require("obj2gltf");
const fs = require("fs");
const options = {
  binary: true,
};
obj2gltf("model.obj", options).then(function (glb) {
  fs.writeFileSync("model.glb", glb);
});

Material types

Traditionally the .mtl file format describes the Blinn-Phong shading model. Meanwhile glTF 2.0 introduces physically-based materials.

There are three shading models supported by obj2gltf:

  • Metallic roughness PBR
  • Specular glossiness PBR (via KHR_materials_pbrSpecularGlossiness extension)
  • Unlit materials (via KHR_materials_unlit extension)

If the material type is known in advance, it should be specified with either the metallicRoughness or specularGlossiness flag.

If lighting information is already present in the model, the unlit flag should be used. This will save the glTF with the KHR_materials_unlit extension.

If the model is created with PBR textures, either the metallicRoughness or specularGlossiness flag should be passed in. See the table below for more information about how to specify PBR values inside the .mtl file.

If none of these flags are provided, the .mtl is assumed to contain traditional Blinn-Phong materials which will be converted to metallic-roughness PBR. There may be some quality loss as traditional materials do not map perfectly to PBR materials.

Commonly in PBR workflows the the .mtl file may not exist or its values may be outdated or incorrect. As a convenience the PBR textures may be supplied directly to the command line.

Mapping of mtl slots to shading models

Slot Metallic roughness Specular glossiness
Ka occlusion value occlusion value
Ke emissive color emissive color
Kd base color diffuse color
Ks metallic value specular color
Ns roughness value glossiness value
d alpha alpha
Tr 1.0 - alpha 1.0 - alpha
map_Ka occlusion texture occlusion texture
map_Ke emissive texture emissive texture
map_Kd base color texture diffuse texture
map_Ks metallic texture specular texture
map_Ns roughness texture glossiness texture
map_Bump normal texture normal texture

Usage

Command line flags:

Flag Description Required
-h, --help Display help. No
-i, --input Path to the obj file. ✅ Yes
-o, --output Path of the converted glTF or glb file. No
-b, --binary Save as binary glTF (.glb). No, default false
-s, --separate Writes out separate buffers and textures instead of embedding them in the glTF file. No, default false
-t, --separateTextures Write out separate textures only. No, default false
--checkTransparency Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel. By default textures are considered to be opaque. No, default false
--secure Prevent the converter from reading texture or mtl files outside of the input obj directory. No, default false
--packOcclusion Pack the occlusion texture in the red channel of metallic-roughness texture. No, default false
--metallicRoughness The values in the mtl file are already metallic-roughness PBR values and no conversion step should be applied. Metallic is stored in the Ks and map_Ks slots and roughness is stored in the Ns and map_Ns slots. No, default false
--specularGlossiness The values in the mtl file are already specular-glossiness PBR values and no conversion step should be applied. Specular is stored in the Ks and map_Ks slots and glossiness is stored in the Ns and map_Ns slots. The glTF will be saved with the KHR_materials_pbrSpecularGlossiness extension. No, default false
--unlit The glTF will be saved with the KHR_materials_unlit extension. No, default false
--metallicRoughnessOcclusionTexture Path to the metallic-roughness-occlusion texture that should override textures in the .mtl file, where occlusion is stored in the red channel, roughness is stored in the green channel, and metallic is stored in the blue channel. The model will be saved with a pbrMetallicRoughness material. This is often convenient in workflows where the .mtl does not exist or is not set up to use PBR materials. Intended for models with a single material. No
--specularGlossinessTexture Path to the specular-glossiness texture that should override textures in the .mtl file, where specular color is stored in the red, green, and blue channels and specular glossiness is stored in the alpha channel. The model will be saved with a material using the KHR_materials_pbrSpecularGlossiness extension. No
--occlusionTexture Path to the occlusion texture that should override textures in the .mtl file. No
--normalTexture Path to the normal texture that should override textures in the .mtl file. No
--baseColorTexture Path to the baseColor/diffuse texture that should override textures in the .mtl file. No
--emissiveTexture Path to the emissive texture that should override textures in the .mtl file. No
--alphaTexture Path to the alpha texture that should override textures in the .mtl file. No
--input-up-axis Up axis of the obj. No
--output-up-axis Up axis of the converted glTF. No
--triangle-winding-order-sanitization Apply triangle winding order sanitization. No
--doubleSidedMaterial Allow the material properties to be double-sided No, default false

Build Instructions

Run the tests:

npm run test

To run ESLint on the entire codebase, run:

npm run eslint

To run ESLint automatically when a file is saved, run the following and leave it open in a console window:

npm run eslint-watch

Running Test Coverage

Coverage uses nyc. Run:

npm run coverage

For complete coverage details, open coverage/lcov-report/index.html.

The tests and coverage covers the Node.js module; it does not cover the command-line interface, which is tiny.

Generating Documentation

To generate the documentation:

npm run jsdoc

The documentation will be placed in the doc folder.

Contributions

Pull requests are appreciated. Please use the same Contributor License Agreement (CLA) used for CesiumJS.


Developed by the Cesium team.

obj2gltf's People

Contributors

analyticalgraphics avatar ankittrehan2000 avatar beesboxler avatar chetan-set avatar ebogo1 avatar emackey avatar freakthemighty avatar ggetz avatar greenkeeper[bot] avatar hawkaa avatar ianlilleyt avatar lasalvavida avatar likangning93 avatar lilleyse avatar mramato avatar ottaviohartman avatar pjcozzi avatar rahwang avatar sanjeetsuhag avatar shehzan10 avatar tfili avatar timknip2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obj2gltf's Issues

Freezing with any command line

Hello! I'm trying to use the tool to convert some 3D objects to GLTF, but I must be doing something wrong, as any command line I try the tool just shows an empty line and freezes until I hit Ctrl C. I installed the tool using the

npm install --save obj2gltf

command line from the instructions.
From there I proceeded to go to the obj2gltf folder inside the "node_modules" folder and, from there, run some command lines, but with all of the the tool just freezes. Even a simple

node bin\obj2gltf.js -h

doesn't work, which is why I think I must be doing something wrong... I'm new to Node.js, so please excuse me if I'm doing something obviously wrong...

Thanks for any help!

Conversion error (after >1 hour of converting)

Here is what I'm trying to convert: https://dl.dropboxusercontent.com/u/705999/Paris.zip

Command I ran
node node_modules/obj2gltf/bin/obj2gltf.js "Paris2010_0.obj" model.gltf -s

After seemingly stuck converting, I decided to let it run for the rest of the day. After about 1.5 hours or so, a js error finally came up:

    { Error
        at new DeveloperError (c:\Users\Flux\Documents\assetdev\Paris\node_modules\cesium\Source\Core\DeveloperError.js:44:19)
        at Object.Tipsify.tipsify (c:\Users\Flux\Documents\assetdev\Paris\node_modules\cesium\Source\Core\Tipsify.js:189:19)
        at Object.GeometryPipeline.reorderForPostVertexCache (c:\Users\Flux\Documents\assetdev\Paris\node_modules\cesium\Source\Core\GeometryPipeline.js:433:40)
        at optimizeForVertexCache (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\lib\optimizeForVertexCache.js:93:38)
        at Function.Pipeline.processJSONWithExtras (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\lib\Pipeline.js:95:5)
        at c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\lib\Pipeline.js:177:29
        at tryCatcher (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\util.js:16:23)
        at Promise._settlePromiseFromHandler (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:504:31)
        at Promise._settlePromise (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:561:18)
        at Promise._settlePromise0 (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:606:10)
        at Promise._settlePromises (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:685:18)
        at Promise._fulfill (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:630:18)
        at Promise._resolveCallback (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:425:57)
        at Promise._settlePromiseFromHandler (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:516:17)
        at Promise._settlePromise (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:561:18)
        at Promise._settlePromise0 (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:606:10)
        at Promise._settlePromises (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:685:18)
        at Promise._fulfill (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:630:18)
        at PromiseArray._resolve (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise_array.js:125:19)
        at PromiseArray._promiseFulfilled (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise_array.js:143:14)
        at Promise._settlePromise (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:566:26)
        at Promise._settlePromise0 (c:\Users\Flux\Documents\assetdev\Paris\node_modules\gltf-pipeline\node_modules\bluebird\js\release\promise.js:606:10)
      name: 'DeveloperError',
      message: 'indices length must be a multiple of three.',
      stack: 'Error\n    at new DeveloperError (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\cesium\\Source\\Core\\DeveloperError.js:44:19)\n    at Object.Tipsify.tipsify (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\cesium\\Source\\Core\\Tipsify.js:189:19)\n    at Object.GeometryPipeline.reorderForPostVertexCache (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\cesium\\Source\\Core\\GeometryPipeline.js:433:40)\n    at optimizeForVertexCache (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\lib\\optimizeForVertexCache.js:93:38)\n    at Function.Pipeline.processJSONWithExtras (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\lib\\Pipeline.js:95:5)\n    at c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\lib\\Pipeline.js:177:29\n    at tryCatcher (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\util.js:16:23)\n    at Promise._settlePromiseFromHandler (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:504:31)\n    at Promise._settlePromise (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:561:18)\n    at Promise._settlePromise0 (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:606:10)\n    at Promise._settlePromises (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:685:18)\n    at Promise._fulfill (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:630:18)\n    at Promise._resolveCallback (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:425:57)\n    at Promise._settlePromiseFromHandler (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:516:17)\n    at Promise._settlePromise (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:561:18)\n    at Promise._settlePromise0 (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:606:10)\n    at Promise._settlePromises (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:685:18)\n    at Promise._fulfill (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:630:18)\n    at PromiseArray._resolve (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise_array.js:125:19)\n    at PromiseArray._promiseFulfilled (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise_array.js:143:14)\n    at Promise._settlePromise (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:566:26)\n    at Promise._settlePromise0 (c:\\Users\\Flux\\Documents\\assetdev\\Paris\\node_modules\\gltf-pipeline\\node_modules\\bluebird\\js\\release\\promise.js:606:10)' }

Any ideas on what could be going wrong? It's not that big of an obj (around 40 mb with 30 mb of textures).

ability to change up axis

A lot of models going through obj2gltf right now come out sideways, since gltf assumes a Y-up axis.
Does obj assume anything? Otherwise, should we add a flag for changing the up axis, along with some notes?

As observed by @mramato, it's probably also better to bake this transformation straight into the geometry by flipping components of vertices rather than slap a rotation quaternion onto the gltf scenegraph.

obj2gltf convert error

convert error:mime must be a string , what this mean :

E:\work\obj2gltf-master\bin>node obj2gltf.js -i gugong/gugong.obj -o gugong/gugong.gltf -s
Error: mime must be a string
at Jimp.throwError (E:\work\obj2gltf-master\node_modules\jimp\index.js:82:43)
at new Jimp (E:\work\obj2gltf-master\node_modules\jimp\index.js:212:31)
at E:\work\obj2gltf-master\node_modules\jimp\index.js:237:23
at Function.Jimp.read (E:\work\obj2gltf-master\node_modules\jimp\index.js:229:19)
at generateJimpImage (E:\work\obj2gltf-master\node_modules\gltf-pipeline\lib\loadGltfUris.js:151:17)
at loadURI (E:\work\obj2gltf-master\node_modules\gltf-pipeline\lib\loadGltfUris.js:79:39)
at loadGltfUris (E:\work\obj2gltf-master\node_modules\gltf-pipeline\lib\loadGltfUris.js:36:9)
at Function.Pipeline.processJSONToDisk (E:\work\obj2gltf-master\node_modules\gltf-pipeline\lib\Pipeline.js:192:12)
at E:\work\obj2gltf-master\lib\convert.js:58:33
at tryCatcher (E:\work\obj2gltf-master\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (E:\work\obj2gltf-master\node_modules\bluebird\js\release\promise.js:510:31)
at Promise._settlePromise (E:\work\obj2gltf-master\node_modules\bluebird\js\release\promise.js:567:18)
at Promise._settlePromise0 (E:\work\obj2gltf-master\node_modules\bluebird\js\release\promise.js:612:10)
at Promise._settlePromises (E:\work\obj2gltf-master\node_modules\bluebird\js\release\promise.js:691:18)
at Async._drainQueue (E:\work\obj2gltf-master\node_modules\bluebird\js\release\async.js:133:16)
at Async._drainQueues (E:\work\obj2gltf-master\node_modules\bluebird\js\release\async.js:143:10)

help:my obj isn't converted correctly

Inconsistency error: this asset probably refers to invalid image Ids within

warning:
PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile PNG lib warning : iCCP: known incorrect sRGB profile

Blender OBJ

How to export OBJ file from Blender to keep meshes separated. If I use OBJ2GLTF -e all meshes will be combined using only one material.

node bin/obj2gltf.js test.obj -e

Thanks for help!
Peter

Cannot read property 'isTTY' of undefined

melkor:/melkor/d1/guenther/projects/threejs/OBJ2GLTF> node bin/obj2gltf.js ../obj/test5.obj ../obj/test5.gltf

readline.js:74
    terminal = !!output.isTTY;
                       ^
TypeError: Cannot read property 'isTTY' of undefined
    at new Interface (readline.js:74:24)
    at Object.exports.createInterface (readline.js:40:10)
    at getObjInfo (/melkor/d1/guenther/projects/threejs/OBJ2GLTF/lib/obj.js:310:27)
    at parseObj (/melkor/d1/guenther/projects/threejs/OBJ2GLTF/lib/obj.js:17:5)
    at convert (/melkor/d1/guenther/projects/threejs/OBJ2GLTF/lib/convert.js:36:5)
    at Object.<anonymous> (/melkor/d1/guenther/projects/threejs/OBJ2GLTF/bin/obj2gltf.js:35:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

gltf are always black and no texture.

success from obj to gltf. But gltf are always black and no texture.
How to check texture coordinate problem and how to solve it.
(some friends said my gltf's Normal coordinate are wrong )

Saves two bin files when separate flag is used

The first is written by obj2gltf prior to sending to gltf-pipeline, and the second is written by gltf-pipeline. This can be solved by removing the first bin file after passing along to gltf-pipeline, or changing gltf-pipeline to use the same naming scheme for separate buffers.

Consider adding flag for KHR_materials_common

Similar to -k in COLLADA2GLTF, which an upcoming PR may rename to -m.

Some A-Frame users have been surprised when lighting/shadows do not work, and three.js has a bug (fixed but not yet released) with glTF custom shaders used in VREffect, so the common materials are preferable in several cases.

OBJ2GLTF can't handle with Tile_+000_+000_0.dds

I have one group file (
Tile_+000_+000_0.obj
Tile_+000_+000_0.mtl ------------(link Tile_+000_+000_0.dds )
Tile_+000_+000_0.dds) .

These files are from osgconv (osgb --> obj)

I don't find any error :\OBJ2GLTF>node bin/obj2gltf.js -i testobj/obj/Tile_+000_+000.obj -o testobj/o
/Tile_+000_+000.gltf -e
otal: 391ms.

But this gltf can't run in ceseam.js (
Error is "images": {
"Tile_+000_+000_0": {
"uri": "data:application/octet-stream;base64,RERTIHwAAAAHEAoAAAE

conversion error "Cannot read property 'buffers' of undefined"

I am getting the following error:

Unhandled rejection TypeError: Cannot read property 'buffers' of undefined
at loadURI (node_modules/obj2gltf/node_modules/gltf-pipeline/lib/loadGltfUris.js:47:23)
at loadGltfUris (node_modules/obj2gltf/node_modules/gltf-pipeline/lib/loadGltfUris.js:35:9)
at Function.Pipeline.processJSONToDisk (node_modules/obj2gltf/node_modules/gltf-pipeline/lib/Pipeline.js:192:12)

Is this a problem with my OBJ file?

Thanks!

Slow Conversion Time

I'm not sure if this is really an issue, but it took 163 minutes to convert a 25mb .obj. Is this normal?

[piero@acer texturing]$ time node test.js
Converted model

real 163m7.272s
user 163m47.696s
sys 0m1.987s

I used this code to convert:

var obj2gltf = require('obj2gltf');
var convert = obj2gltf.convert;
var options = {
	    embedImage : true // Don't embed image in the converted glTF
}
convert('odm_textured_model_geo.obj', 'model.gltf', options)
    .then(function() {
	            console.log('Converted model');
	        });

There were some ~30mb of textures embedded.

Is there a way to speed things up?

ThreeJS GLTF Loader Fails

Hello! I'm trying to load in a GLTF file converted from obj with Three.JS, however it complains when it tries to unpack the buffer that holds the geometry.
screen shot 2016-06-23 at 5 51 41 pm
screen shot 2016-06-23 at 5 55 07 pm

The componentType seems to not match any of the builtin ones (such as WebGLRenderingContext.FLOAT, etc)

Would appreciate any guidance/help.

Texture coordinates are flipped vertically

This has already been mentioned in #6 . The recommendation there was to flip the input image vertically. But this seems to be a dubious workaround.

Attached is a file that contains the Duck, as an OBJ. This OBJ is displayed properly in http://www.open3mod.com/ and http://meshlab.sourceforge.net/ . Converting it with OBJ2GLTF results in the second attached file (where I only fixed CesiumGS/gltf-pipeline#114 in the shader manually). In this glTF, the texture coordinates are flipped vertically. (I only checked this with my own glTF viewer, but it properly displays Duck model from the glTF samples, so something must be wrong with the converted one...)

DuckObj.zip
DuckGltf.zip

convert issue

I try to convert some files from obj to gltf.prompt "[TypeError: Object has no method 'fill']" . Looks like the tool has a problem. All steps use npm install. How can i fix it?

Node string limitations

Buffers larger than ~192MB cannot be base64 encoded due to a NodeJS limitation. nodejs/node#4266

It would be good to get around this. In most cases however using the --separate flag is the way go.

Add support for Nodes

It seems that currently the obj2gltf conversion does not include the transforms / pivots / matrices of the obj file. Adding this would make this tool a whole lot more useful.

Remove git dependancy in package.json

  1. We should never use a git dependancy without a specific hash appended to it, otherwise you end up just using whatever is in master wen you npm install.
  2. We should never merge a package.json with git references to master. Package in master should either be published npm modules or git submodules.

UV's are discarded if no material is referenced in .obj

As an addendum to #32, I've found that obj2gltf (via gltf-pipeline) is discarding my UV's (vt data from .obj), this was why I was struggling to get glTF to render in three.js - I thought the issue was confusion over default materials loaded from the glTF but really it just didn't have an texture coordinates so materials were appearing as solid colour instead of textured. Example source .obj and output gltf attached. I need an option to preserve that information as I am texture mapping based on user choices in the browser.

body-top.zip

Problem with missing dependencies

melkor:/melkor/d1/guenther/projects/threejs/OBJ2GLTF> node bin/obj2gltf.js ../obj/test5.obj ../obj/test5.gltf

module.js:340
    throw err;
          ^
Error: Cannot find module 'Cesium'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/melkor/d1/guenther/projects/threejs/OBJ2GLTF/bin/obj2gltf.js:4:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

So, I tried to install Cesium, but that failed:

melkor:/melkor/d1/guenther/projects/threejs/OBJ2GLTF> npm install Cesium        
npm http GET https://registry.npmjs.org/Cesium
npm http 404 https://registry.npmjs.org/Cesium
npm ERR! TypeError: Cannot read property 'latest' of undefined
npm ERR!     at next (/usr/lib/node_modules/npm/lib/cache.js:687:35)
npm ERR!     at /usr/lib/node_modules/npm/lib/cache.js:675:5
npm ERR!     at saved (/usr/lib/node_modules/npm-registry-client/lib/get.js:148:7)
npm ERR!     at /usr/lib/node_modules/graceful-fs/polyfills.js:133:7
npm ERR!     at Object.oncomplete (fs.js:108:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.10.0-327.13.1.el7.x86_64
npm ERR! command "node" "/usr/bin/npm" "install" "Cesium"
npm ERR! cwd /melkor/d1/guenther/projects/threejs/OBJ2GLTF
npm ERR! node -v v0.10.42
npm ERR! npm -v 1.3.6
npm ERR! type non_object_property_load
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /melkor/d1/guenther/projects/threejs/OBJ2GLTF/npm-debug.log
npm ERR! not ok code 0

Converted models are washed out by ambient settings

We've discussed this offline, but I couldn't find an issue for it. I've come across quite a few obj files with their ambient values set to 1.0 1.0 1.0, which looks like we translate into additive values in the glTF when they were intended as multiplicative values. The end result is a model with washed out textures.

I believe @lilleyse suggested we keep using additive but discarding "full-white" values of 1.0 1.0 1.0.

I tried to find a clear answer in the obj/mtl spec, but it wasn't very helpful.

These same obj models load fine in Three.js without being washed out, so it's also either ignoring the values or always treating them as multiplicative.

CC @lilleyse @likangning93

npm install failed

D:\workspace>npm install --save obj2gltf
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "D:\\app\\nodejs\\node.exe" "D:\\app\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "obj2gltf"
npm ERR! node v6.10.2
npm ERR! npm  v3.10.10

npm ERR! shasum check failed for C:\Users\bugki\AppData\Local\Temp\npm-11172-df6ce304\registry.npmjs.org\cesium\-\cesium-1.33.0.tgz
npm ERR! Expected: c2471be888dad49a45d47a28cd8c2742eccc34ef
npm ERR! Actual:   1e0a0de7817d955da39ae12cea62cd755325a813
npm ERR! From:     https://registry.npmjs.org/cesium/-/cesium-1.33.0.tgz
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     D:\workspace\npm-debug.log

too much error

\OBJ2GLTF\node_modules\gltf-pipeline\lib\findAccessorMinMax.js:17
var min = new Array(numberOfComponents).fill(Number.POSITIVE_INFINITY);
^
peError: Object has no method 'fill'
at findAccessorMinMax (C:\OBJ2GLTF\node_modules\gltf-pipeline\lib\findAccess
MinMax.js:17:45)
at accessorDefaults (C:\OBJ2GLTF\node_modules\gltf-pipeline\lib\addDefaults.
:24:30)
at addDefaults (C:\OBJ2GLTF\node_modules\gltf-pipeline\lib\addDefaults.js:56
5)
at processJSONWithExtras (C:\OBJ2GLTF\node_modules\gltf-pipeline\lib\gltfPip
ine.js:62:5)
at C:\OBJ2GLTF\node_modules\gltf-pipeline\lib\gltfPipeline.js:145:9
at C:\OBJ2GLTF\node_modules\gltf-pipeline\lib\loadGltfUris.js:36:9
at C:\OBJ2GLTF\node_modules\async\lib\async.js:52:16
at done (C:\OBJ2GLTF\node_modules\async\lib\async.js:246:17)
at C:\OBJ2GLTF\node_modules\async\lib\async.js:4

Not working when used as a library inside an existing Node.js app

I have a project that generates models using OpenDroneMap, and I'm trying to convert those .obj models to be viewable on the web. I can view the .obj models using meshlab without any issues. When I try to use obj2gltf to convert them as part of my workflow inside of a Node.js app, it does nothing. I never get any response from the promise (no success, no error), and no console output. It just hangs. I left it running for about 20 minutes to see if it was just taking a really long time, but finally killed it when nothing happened.

My code looks like this:

var filePrefix = __dirname + "/" + rootDirName + "/" + currentDocument.id + '/odm_texturing/odm_textured_model_geo';
var options = {
    embedImage : false // Don't embed image in the converted glTF
}
var objFile = filePrefix +'.obj';
var gltfFile = filePrefix +'.gltf';
console.log(objFile);
console.log(gltfFile);

convert(objFile, gltfFile, options)
    .then(function() {
        console.log('Converted model');
        callback();
    })
    .catch(function(err){
        console.log("ERROR:" + err.toString());
        callback(err);
    });

My output only shows the file names, nothing else:

/root/analysis-baremetal/temp/6f5ddb39312feefc5e37bad7baf71cdd/odm_texturing/odm_textured_model_geo.obj
/root/analysis-baremetal/temp/6f5ddb39312feefc5e37bad7baf71cdd/odm_texturing/odm_textured_model_geo.gltf

I assume this is just failing silently - there are no other indications of an error, and no stack trace. The .obj file is about 25 MB, which isn't tiny, but again, it also is not huge so I wouldn't expect it to take this long.

Crash when flag bypassPipeline is used

I'm getting this output when using bypassPipeline.

node ~/lib/obj2gltf/bin/obj2gltf.js -i box.obj -o sample.glb -b --bypassPipeline

~/node_modules/cesium/Source/ThirdParty/crunch.js:43
    var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](filename);if(!ret&&filename!=nodePath["resolve"]
Error
    at new DeveloperError (~/node_modules/cesium/Source/Core/DeveloperError.js:44:19)
    at obj2gltf (~/lib/obj2gltf/lib/obj2gltf.js:88:15)
    at Object.<anonymous> (~/lib/obj2gltf/bin/obj2gltf.js:141:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

I tried both with 1.1.1 and master branch as of today. cesium version is 1.32.1

conversion error

I've installed obj2gltf v0.1.7 using npm install -g obj2gltf.
My node version is v7.5.0.
When I try to convert my file wall_and_door.obj, which you can find at https://github.com/andyli/aframe-test/tree/1fe0f0cc8af332b9a8c7880437a8678e99e3b6e2/wall_and_door, there is an error:

D:\andy\workspace\VRWorkshop\wall_and_door>obj2gltf wall_and_door.obj

C:\ProgramData\nvm\v7.5.0\node_modules\obj2gltf\node_modules\cesium\Source\ThirdParty\crunch.js:43
    var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](filename);if(!ret&&filename!=no
Error
    at new DeveloperError (C:\ProgramData\nvm\v7.5.0\node_modules\obj2gltf\node_modules\cesium\Source\Core\DeveloperError.js:44:19)
    at Function.Cartesian3.normalize (C:\ProgramData\nvm\v7.5.0\node_modules\obj2gltf\node_modules\cesium\Source\Core\Cartesian3.js:422:19)
    at LineStream.<anonymous> (C:\ProgramData\nvm\v7.5.0\node_modules\obj2gltf\lib\obj.js:192:41)
    at emitOne (events.js:96:13)
    at LineStream.emit (events.js:189:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at LineStream.Readable.push (_stream_readable.js:134:10)
    at LineStream.Transform.push (_stream_transform.js:128:32)
    at LineStream._pushBuffer (C:\ProgramData\nvm\v7.5.0\node_modules\obj2gltf\node_modules\byline\lib\byline.js:126:17)
    at LineStream._transform (C:\ProgramData\nvm\v7.5.0\node_modules\obj2gltf\node_modules\byline\lib\byline.js:117:8)
    at LineStream.Transform._read (_stream_transform.js:167:10)
    at LineStream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:329:12)
    at writeOrBuffer (_stream_writable.js:315:5)
    at LineStream.Writable.write (_stream_writable.js:241:11)
    at ReadStream.ondata (_stream_readable.js:555:20)

Conversion Always Missing One Box.

draw some boxes in 3ds max 2015,for example,draw six boxes and export as an OBJ file as show below. Then, use the obj2gltf tool to convert this OBJ file to binary gltf and load it in Cesium, as show below, there is always one box missing! Only five boxes instead of six box are in the scene. I have tried other cases like five or seven boxes, after the conversion, always one box was gone.

sixbox_3dsmax2015
fivebox_cesium

Implement feature to export geometry only

Currently when I use this tool to convert a .obj (geometry only export from Rhino3D) it introduces default materials and shaders. I'm assuming it does this so that the model will show up in a simple glTF viewer. I'm using glTF as a model format and then applying materials and shader (in three.js) programatically.

Could we/should we have an option to export a .gltf with only geometry/nodes/meshes (discarding shaders and materials)?

Consider replacing period usage in command line parameters

I noticed we have periods in our cmd arguments, for example --ao.enable. It's standard to use a hyphen to separate words, I've never seen periods used like this: --ao-enable. Hyphens are standard enough that yargs automatically duplicated this to aoEnable on the parsed object to make it easily indexable from JavaScript without having string literals everywhere.

Ability to find external files and textures

I have models where the obj paths are incorrect or absolute but the files themselves are all there and located in the same directory as the obj file. It would be great if we either:

  • Always looked in the same directory as the obj file if the initial texture/mtl/etc.. isn't where the model says it should be.

or

  • Allowed an array of directories to be passed to the converter and it would search those directories for the file is not found in the obj specified location.

The first one is probably easier and I'm fine with that until we have a good use case for the more robust feature.

What texture formats are currently supported?

I couldn't find what texture formats are currently supported for input files. We should update the README with an exact list.

It would be nice if we could auto-convert textures to glTF friendly formats, perhaps via imagemagick or whatever node-friendly libraries are available.

Windows line endings break #! parsing on Linux

Although the git repo has unix-style line endings, the version of obj2gltf on npm has Windows line endings. When running the command line tool the extra \r confuses the Linux #! parser:

$ lsb_release -d
Description:    Ubuntu 16.04.1 LTS

$ npm install -g obj2gltf
[...]

$ obj2gltf
/usr/bin/env: ‘node\r’: No such file or directory

$ dos2unix ~/.local/node/lib/node_modules/obj2gltf/bin/obj2gltf.js
dos2unix: converting file /home/josh/.local/node/lib/node_modules/obj2gltf/bin/obj2gltf.js to Unix format ...

$ obj2gltf
Usage: ./bin/obj2gltf.js [INPUT] [OPTIONS]
[...]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.