Converter from Wavefront OBJ to JavaScript Object Notation

1

Today I would like to introduce a converter of 3D objects to JavaScript. The converter creates a JavaScript Object Notation file from a Wavefront OBJ file .

What is Wavefront OBJ?

OBJ (or .obj) is an open file format for storing three-dimensional geometric shapes. The format developed by Wavefront Technologies is supported by many 3D graphics programs and is therefore suitable for the cross-platform and cross-platform distribution of 3D models.

The OBJ format stores geometric properties of an object or grouped objects, ie, corners, texture coordinates, normals, surfaces, and smoothers. Optical material properties (eg mirroring, transparency, highlight, etc.) are defined in a separate material file, which may also contain information on texturing. The material file usually has the file extension .mtl (from English material template library) and can be referenced in the actual OBJ file.

What is JavaScript Object Notation?

JavaScript Object Notation, or JSON [dʒeɪsən] for short, is a compact data format in an easy-to-read text form for the purpose of data exchange between applications. Each valid JSON document should be a valid JavaScript and can be interpreted by eval (). Due to small deviations in the set of allowed Unicode characters, however, it is possible to generate JSON objects that are not accepted by a JavaScript conformant JavaScript interpreter. [1] Apart from that, JSON is independent of the programming language. Pars exist in virtually all common languages.

How to use this converter

python convert_obj_three.py -i teapot.obj -o teapot.js

python convert_obj_three.py -i infile.obj -o outfile.js [-m “morphfiles * .obj”] [-c “morphcolors * .obj”] [-a center | centerxz | top | bottom | none] [-s smooth | flat] [-t ascii | binary] [-d invert | normal] [-b] [-e]

Notizen:
- flags
-i infile.obj Eingabe OBJ-Datei
-o outfile.js Ausgabe JS-Datei
-m "morphfiles * .obj" morph OBJ-Dateien (können Platzhalter verwenden, eingeschlossen in Anführungszeichen mehrere Muster durch Leerzeichen getrennt)
-c "morphcolors * .obj" morph Farben OBJ-Dateien (können Platzhalter verwenden, eingeschlossen in Anführungszeichen mehrere Muster getrennt durch Leerzeichen)
-a center | centerxz | top | bottom | none Modellausrichtung
-s smooth | flatsmooth= Exportscheitel-Normalen, flach = keine Normalen (im Loader berechnete Flächennormalen)
-t ascii | binary ascii oder Binärformat (ascii hat mehr Funktionen, binäre nur unterstützt Scheitel, Gesichter, Normalen, UV-und Material)
-b backen Materialfarben in Gesichtfarben
-x 10.0 Maßstab und trunkate
-f 2-Morph-Frame-Abtastschritt

- standardmäßig:
Verwenden Sie glatte Schattierung (wenn es Scheitel Normalen in der ursprünglichen Modell)
Wird im ASCII-Format sein
Keine Gesichtsfarben backen
Keine Skala und trunkate
Morph frame step = 1 (alle Dateien werden verarbeitet)

- Binär-Konvertierung erstellt zwei Dateien:
Outfile.js (Materialien)
Outfile.bin (binäre Puffer)

Use the generated JS file in your HTML document

 

<script type="text/javascript" src="Three.js"></script>

...

<script type="text/javascript">
...

// load ascii model

var jsonLoader = new THREE.JSONLoader();
jsonLoader.load( "Model_ascii.js", createScene );

// load binary model

var binLoader = new THREE.BinaryLoader();
binLoader.load( "Model_bin.js", createScene );

function createScene( geometry, materials ) {

var mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );

}

...
</script>

 

Share This:

1 Comment

  1. Pingback: Converter from Wavefront OBJ to JavaScript Object Notation – Javascript World

Leave A Reply

Powered by FrontNet