Skip to content
This repository was archived by the owner on Dec 19, 2021. It is now read-only.

Commit

Permalink
feat: change to "convert glb to wdb"
Browse files Browse the repository at this point in the history
upgrade wonder.js
  • Loading branch information
yyc-git committed Jul 4, 2018
1 parent 4364b71 commit 1c4adc7
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 208 deletions.
6 changes: 3 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ var gulp = require("gulp");

var commandUtils = require("./build/gulp_task/common/commandUtils");

var convert = require("./lib/js/src/ConvertGLTFToWDSystem.js");
var convert = require("./lib/js/src/ConvertGLBToWDBSystem.js");

gulp.task("convert", function (done) {
var sourceGLTFFilePath = commandUtils.parseOption("--sourceGLTFFilePath"),
var sourceGLTFFilePath = commandUtils.parseOption("--sourceGLBFilePath"),
destDir = commandUtils.parseOption("--destDir") || "./dest/";

if (destDir === null) {
throw new Error("should define --sourceGLTFFilePath");
throw new Error("should define --sourceGLBFilePath");
}

convert.convert(sourceGLTFFilePath, destDir);
Expand Down
67 changes: 67 additions & 0 deletions src/ConvertGLBToWDBSystem.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
open Wonderjs;

open Node;

let convertUint8ArrayToBuffer = [%raw
uint8Array => {|
{
var buf = new Buffer(uint8Array.byteLength);
for (var i = 0; i < buf.length; ++i) {
buf[i] = uint8Array[i];
}
return buf;
}
|}
];

let buildFakeTextDecoder = [%raw
convertUint8ArrayToBufferFunc => {|
var TextDecoder = function(utfLabel){
};
TextDecoder.prototype.decode = (uint8Array) => {
var buffer = convertUint8ArrayToBufferFunc(uint8Array);
return buffer.toString("utf8");
};
global.TextDecoder = TextDecoder;
|}
];

let buildFakeTextEncoder =
[@bs]
[%raw
() => {|
var TextEncoder = function(){
};
TextEncoder.prototype.encode = (str) => {
var buffer = Buffer.from(str, "utf8");
return buffer;
};
global.TextEncoder = TextEncoder;
|}
];


let _buildWDBFilePath = (sourceGLBFilePath, destDir) =>
Path.join([|
destDir,
Path.basename_ext(sourceGLBFilePath, ".glb") ++ ".wdb",
|]);

let convert = (sourceGLBFilePath, destDir) => {
let buffer = NodeExtend.readFileBufferSync(sourceGLBFilePath);

buildFakeTextDecoder(convertUint8ArrayToBuffer);
buildFakeTextEncoder(.);

buffer##buffer
|> ConverterAPI.convertGLBToWDB
|> WriteWDBSystem.write(_buildWDBFilePath(sourceGLBFilePath, destDir));
};
11 changes: 0 additions & 11 deletions src/ConvertGLTFToWDSystem.re

This file was deleted.

12 changes: 12 additions & 0 deletions src/NodeExtend.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[@bs.module "fs"]
external readFileBufferSync : string => 'buffer = "readFileSync";

[@bs.module "fs"]
external writeFileBufferSync :
(string, 'buffer, [@bs.string] [ | `binary]) => unit =
"writeFileSync";

[@bs.new]
external newBufferFromArrayBuffer :
Js.Typed_array.ArrayBuffer.t => Node.Buffer.t =
"Buffer";
6 changes: 6 additions & 0 deletions src/WriteWDBSystem.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let write = (targetFilePath, wdb) =>
NodeExtend.writeFileBufferSync(
targetFilePath,
NodeExtend.newBufferFromArrayBuffer(wdb),
`binary,
);
7 changes: 0 additions & 7 deletions src/WriteWDSystem.re

This file was deleted.

11 changes: 5 additions & 6 deletions test/integration/convert_test.re

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions test/integration/tool/ConvertTool.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Wonderjs;

let readWDB = wdbFilePath => {
let buffer = NodeExtend.readFileBufferSync(wdbFilePath);

buffer##buffer;
};

let getWDFileContent = wdb => {
let (wdFileContent, _) =
BinaryUtils.decode(wdb, AssembleWDBSystem._checkWDB);

wdFileContent;
};
Binary file added test/res/BoxTextured.glb
Binary file not shown.
181 changes: 0 additions & 181 deletions test/res/BoxTextured.gltf

This file was deleted.

0 comments on commit 1c4adc7

Please sign in to comment.