Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Convert exporters to ES6. #21605

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 82 additions & 84 deletions examples/js/exporters/ColladaExporter.js

Large diffs are not rendered by default.

76 changes: 35 additions & 41 deletions examples/js/exporters/DRACOExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
*/

/* global DracoEncoderModule */
var DRACOExporter = function () {};

DRACOExporter.prototype = {
constructor: DRACOExporter,
parse: function ( object, options ) {
class DRACOExporter {

parse( object, options = {
decodeSpeed: 5,
encodeSpeed: 5,
encoderMethod: DRACOExporter.MESH_EDGEBREAKER_ENCODING,
quantization: [ 16, 8, 8, 8, 8 ],
exportUvs: true,
exportNormals: true,
exportColor: false
} ) {

if ( object.isBufferGeometry === true ) {

Expand All @@ -33,25 +39,11 @@

}

if ( options === undefined ) {

options = {
decodeSpeed: 5,
encodeSpeed: 5,
encoderMethod: DRACOExporter.MESH_EDGEBREAKER_ENCODING,
quantization: [ 16, 8, 8, 8, 8 ],
exportUvs: true,
exportNormals: true,
exportColor: false
};

}

var geometry = object.geometry;
var dracoEncoder = DracoEncoderModule();
var encoder = new dracoEncoder.Encoder();
var builder;
var dracoObject;
const geometry = object.geometry;
const dracoEncoder = DracoEncoderModule();
const encoder = new dracoEncoder.Encoder();
let builder;
let dracoObject;

if ( geometry.isBufferGeometry !== true ) {

Expand All @@ -63,19 +55,19 @@

builder = new dracoEncoder.MeshBuilder();
dracoObject = new dracoEncoder.Mesh();
var vertices = geometry.getAttribute( 'position' );
const vertices = geometry.getAttribute( 'position' );
builder.AddFloatAttributeToMesh( dracoObject, dracoEncoder.POSITION, vertices.count, vertices.itemSize, vertices.array );
var faces = geometry.getIndex();
const faces = geometry.getIndex();

if ( faces !== null ) {

builder.AddFacesToMesh( dracoObject, faces.count / 3, faces.array );

} else {

var faces = new ( vertices.count > 65535 ? Uint32Array : Uint16Array )( vertices.count );
const faces = new ( vertices.count > 65535 ? Uint32Array : Uint16Array )( vertices.count );

for ( var i = 0; i < faces.length; i ++ ) {
for ( let i = 0; i < faces.length; i ++ ) {

faces[ i ] = i;

Expand All @@ -87,7 +79,7 @@

if ( options.exportNormals === true ) {

var normals = geometry.getAttribute( 'normal' );
const normals = geometry.getAttribute( 'normal' );

if ( normals !== undefined ) {

Expand All @@ -99,7 +91,7 @@

if ( options.exportUvs === true ) {

var uvs = geometry.getAttribute( 'uv' );
const uvs = geometry.getAttribute( 'uv' );

if ( uvs !== undefined ) {

Expand All @@ -111,7 +103,7 @@

if ( options.exportColor === true ) {

var colors = geometry.getAttribute( 'color' );
const colors = geometry.getAttribute( 'color' );

if ( colors !== undefined ) {

Expand All @@ -125,12 +117,12 @@

builder = new dracoEncoder.PointCloudBuilder();
dracoObject = new dracoEncoder.PointCloud();
var vertices = geometry.getAttribute( 'position' );
const vertices = geometry.getAttribute( 'position' );
builder.AddFloatAttribute( dracoObject, dracoEncoder.POSITION, vertices.count, vertices.itemSize, vertices.array );

if ( options.exportColor === true ) {

var colors = geometry.getAttribute( 'color' );
const colors = geometry.getAttribute( 'color' );

if ( colors !== undefined ) {

Expand All @@ -147,10 +139,10 @@
} //Compress using draco encoder


var encodedData = new dracoEncoder.DracoInt8Array(); //Sets the desired encoding and decoding speed for the given options from 0 (slowest speed, but the best compression) to 10 (fastest, but the worst compression).
const encodedData = new dracoEncoder.DracoInt8Array(); //Sets the desired encoding and decoding speed for the given options from 0 (slowest speed, but the best compression) to 10 (fastest, but the worst compression).

var encodeSpeed = options.encodeSpeed !== undefined ? options.encodeSpeed : 5;
var decodeSpeed = options.decodeSpeed !== undefined ? options.decodeSpeed : 5;
const encodeSpeed = options.encodeSpeed !== undefined ? options.encodeSpeed : 5;
const decodeSpeed = options.decodeSpeed !== undefined ? options.decodeSpeed : 5;
encoder.SetSpeedOptions( encodeSpeed, decodeSpeed ); // Sets the desired encoding method for a given geometry.

if ( options.encoderMethod !== undefined ) {
Expand All @@ -163,7 +155,7 @@

if ( options.quantization !== undefined ) {

for ( var i = 0; i < 5; i ++ ) {
for ( let i = 0; i < 5; i ++ ) {

if ( options.quantization[ i ] !== undefined ) {

Expand All @@ -175,7 +167,7 @@

}

var length;
let length;

if ( object.isMesh === true ) {

Expand All @@ -196,9 +188,9 @@
} //Copy encoded data to buffer.


var outputData = new Int8Array( new ArrayBuffer( length ) );
const outputData = new Int8Array( new ArrayBuffer( length ) );

for ( var i = 0; i < length; i ++ ) {
for ( let i = 0; i < length; i ++ ) {

outputData[ i ] = encodedData.GetValue( i );

Expand All @@ -210,7 +202,9 @@
return outputData;

}
}; // Encoder methods

} // Encoder methods


DRACOExporter.MESH_EDGEBREAKER_ENCODING = 1;
DRACOExporter.MESH_SEQUENTIAL_ENCODING = 0; // Geometry type
Expand Down
Loading