mirror of
https://github.com/openharmony/third_party_meshoptimizer.git
synced 2026-07-19 12:03:07 -04:00
js: Reformat all sources with Prettier
This commit is contained in:
+53
-52
@@ -1,66 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>meshoptimizer - demo</title>
|
||||
<title>meshoptimizer - demo</title>
|
||||
|
||||
<script src="https://preview.babylonjs.com/babylon.js"></script>
|
||||
<script src="https://preview.babylonjs.com/loaders/babylon.glTF2FileLoader.js"></script>
|
||||
<script src="https://preview.babylonjs.com/babylon.js"></script>
|
||||
<script src="https://preview.babylonjs.com/loaders/babylon.glTF2FileLoader.js"></script>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#renderCanvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
touch-action: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="renderCanvas"></canvas>
|
||||
<script>
|
||||
// Optional - by default Babylon.JS will use bundled decoder module
|
||||
BABYLON.GLTF2.Loader.Extensions.EXT_meshopt_compression.DecoderPath = '../js/meshopt_decoder.module.js';
|
||||
#renderCanvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
touch-action: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="renderCanvas"></canvas>
|
||||
<script>
|
||||
// Optional - by default Babylon.JS will use bundled decoder module
|
||||
BABYLON.GLTF2.Loader.Extensions.EXT_meshopt_compression.DecoderPath = '../js/meshopt_decoder.module.js';
|
||||
|
||||
var canvas = document.getElementById("renderCanvas");
|
||||
var canvas = document.getElementById('renderCanvas');
|
||||
|
||||
var createScene = function () {
|
||||
var scene = new BABYLON.Scene(engine);
|
||||
var createScene = function () {
|
||||
var scene = new BABYLON.Scene(engine);
|
||||
|
||||
var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 10, BABYLON.Vector3.Zero(), scene);
|
||||
camera.attachControl(canvas, false);
|
||||
var camera = new BABYLON.ArcRotateCamera('Camera', 0, 0.8, 10, BABYLON.Vector3.Zero(), scene);
|
||||
camera.attachControl(canvas, false);
|
||||
|
||||
BABYLON.SceneLoader.Append("", "pirate.glb", scene, function (newMeshes) {
|
||||
scene.activeCamera = null;
|
||||
scene.createDefaultCameraOrLight(true);
|
||||
scene.activeCamera.attachControl(canvas, false);
|
||||
scene.activeCamera.alpha = Math.PI / 2;
|
||||
});
|
||||
BABYLON.SceneLoader.Append('', 'pirate.glb', scene, function (newMeshes) {
|
||||
scene.activeCamera = null;
|
||||
scene.createDefaultCameraOrLight(true);
|
||||
scene.activeCamera.attachControl(canvas, false);
|
||||
scene.activeCamera.alpha = Math.PI / 2;
|
||||
});
|
||||
|
||||
return scene;
|
||||
}
|
||||
return scene;
|
||||
};
|
||||
|
||||
var engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
|
||||
var scene = createScene();
|
||||
var engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
|
||||
var scene = createScene();
|
||||
|
||||
engine.runRenderLoop(function () {
|
||||
if (scene) {
|
||||
scene.render();
|
||||
}
|
||||
});
|
||||
engine.runRenderLoop(function () {
|
||||
if (scene) {
|
||||
scene.render();
|
||||
}
|
||||
});
|
||||
|
||||
// Resize
|
||||
window.addEventListener("resize", function () {
|
||||
engine.resize();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
// Resize
|
||||
window.addEventListener('resize', function () {
|
||||
engine.resize();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+32
-25
@@ -1,9 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>meshoptimizer - demo</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
@@ -19,9 +19,15 @@
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
z-index: 100;
|
||||
display:block;
|
||||
display: block;
|
||||
}
|
||||
#info a,
|
||||
.button {
|
||||
color: #f00;
|
||||
font-weight: bold;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
|
||||
</style>
|
||||
|
||||
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
|
||||
@@ -37,7 +43,7 @@
|
||||
|
||||
<body>
|
||||
<div id="info">
|
||||
<a href="https://github.com/zeux/meshoptimizer" target="_blank" rel="noopener">meshoptimizer</a>
|
||||
<a href="https://github.com/zeux/meshoptimizer" target="_blank" rel="noopener">meshoptimizer</a>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
@@ -55,8 +61,7 @@
|
||||
init();
|
||||
animate();
|
||||
|
||||
function init()
|
||||
{
|
||||
function init() {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
@@ -82,21 +87,26 @@
|
||||
|
||||
var loader = new GLTFLoader();
|
||||
loader.setMeshoptDecoder(MeshoptDecoder);
|
||||
loader.load('pirate.glb', function (gltf) {
|
||||
var bbox = new THREE.Box3().setFromObject(gltf.scene);
|
||||
var scale = 2 / (bbox.max.y - bbox.min.y);
|
||||
loader.load(
|
||||
'pirate.glb',
|
||||
function (gltf) {
|
||||
var bbox = new THREE.Box3().setFromObject(gltf.scene);
|
||||
var scale = 2 / (bbox.max.y - bbox.min.y);
|
||||
|
||||
gltf.scene.scale.set(scale, scale, scale);
|
||||
gltf.scene.position.set(0, 0, 0);
|
||||
gltf.scene.scale.set(scale, scale, scale);
|
||||
gltf.scene.position.set(0, 0, 0);
|
||||
|
||||
scene.add(gltf.scene);
|
||||
scene.add(gltf.scene);
|
||||
|
||||
mixer = new THREE.AnimationMixer(gltf.scene);
|
||||
mixer = new THREE.AnimationMixer(gltf.scene);
|
||||
|
||||
if (gltf.animations.length) {
|
||||
mixer.clipAction(gltf.animations[gltf.animations.length - 1]).play();
|
||||
}
|
||||
}, onProgress, onError);
|
||||
if (gltf.animations.length) {
|
||||
mixer.clipAction(gltf.animations[gltf.animations.length - 1]).play();
|
||||
}
|
||||
},
|
||||
onProgress,
|
||||
onError,
|
||||
);
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setPixelRatio(window.devicePixelRatio);
|
||||
@@ -108,8 +118,7 @@
|
||||
clock = new THREE.Clock();
|
||||
}
|
||||
|
||||
function onWindowResize()
|
||||
{
|
||||
function onWindowResize() {
|
||||
windowHalfX = window.innerWidth / 2;
|
||||
windowHalfY = window.innerHeight / 2;
|
||||
|
||||
@@ -119,8 +128,7 @@
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
}
|
||||
|
||||
function animate()
|
||||
{
|
||||
function animate() {
|
||||
if (mixer) {
|
||||
mixer.update(clock.getDelta());
|
||||
}
|
||||
@@ -129,8 +137,7 @@
|
||||
render();
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
function render() {
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
</script>
|
||||
|
||||
+79
-60
@@ -1,9 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>meshoptimizer - demo</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
@@ -19,9 +19,15 @@
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
z-index: 100;
|
||||
display:block;
|
||||
display: block;
|
||||
}
|
||||
#info a,
|
||||
.button {
|
||||
color: #f00;
|
||||
font-weight: bold;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
|
||||
</style>
|
||||
|
||||
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
|
||||
@@ -37,7 +43,7 @@
|
||||
|
||||
<body>
|
||||
<div id="info">
|
||||
<a href="https://github.com/zeux/meshoptimizer" target="_blank" rel="noopener">meshoptimizer</a>
|
||||
<a href="https://github.com/zeux/meshoptimizer" target="_blank" rel="noopener">meshoptimizer</a>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
@@ -62,10 +68,10 @@
|
||||
normalWeight: 0.01,
|
||||
colorWeight: 0.01,
|
||||
|
||||
loadFile: function() {
|
||||
loadFile: function () {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.onchange = function() {
|
||||
input.onchange = function () {
|
||||
var uri = URL.createObjectURL(input.files[0]);
|
||||
|
||||
load(uri);
|
||||
@@ -74,10 +80,10 @@
|
||||
input.click();
|
||||
},
|
||||
|
||||
updateModule: function() {
|
||||
updateModule: function () {
|
||||
reload();
|
||||
simplify();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var gui = new GUI({ width: 300 });
|
||||
@@ -113,46 +119,58 @@
|
||||
|
||||
var positions = new Float32Array(geo.attributes.position.array);
|
||||
var indices = geo.index.original;
|
||||
var target = Math.floor(indices.length * settings.ratio / 3) * 3;
|
||||
var target = Math.floor((indices.length * settings.ratio) / 3) * 3;
|
||||
|
||||
if (settings.useAttributes)
|
||||
{
|
||||
if (settings.useAttributes) {
|
||||
var attrib = new Float32Array(geo.attributes.position.count * attributes);
|
||||
|
||||
for (var i = 0, e = geo.attributes.position.count; i < e; ++i)
|
||||
{
|
||||
for (var i = 0, e = geo.attributes.position.count; i < e; ++i) {
|
||||
if (geo.attributes.normal) {
|
||||
attrib[i*attributes+0] = geo.attributes.normal.getX(i);
|
||||
attrib[i*attributes+1] = geo.attributes.normal.getY(i);
|
||||
attrib[i*attributes+2] = geo.attributes.normal.getZ(i);
|
||||
attrib[i * attributes + 0] = geo.attributes.normal.getX(i);
|
||||
attrib[i * attributes + 1] = geo.attributes.normal.getY(i);
|
||||
attrib[i * attributes + 2] = geo.attributes.normal.getZ(i);
|
||||
}
|
||||
|
||||
if (geo.attributes.color) {
|
||||
attrib[i*attributes+3] = geo.attributes.color.getX(i);
|
||||
attrib[i*attributes+4] = geo.attributes.color.getY(i);
|
||||
attrib[i*attributes+5] = geo.attributes.color.getZ(i);
|
||||
attrib[i * attributes + 3] = geo.attributes.color.getX(i);
|
||||
attrib[i * attributes + 4] = geo.attributes.color.getY(i);
|
||||
attrib[i * attributes + 5] = geo.attributes.color.getZ(i);
|
||||
}
|
||||
}
|
||||
|
||||
var attrib_weights = [
|
||||
settings.normalWeight, settings.normalWeight, settings.normalWeight,
|
||||
settings.colorWeight, settings.colorWeight, settings.colorWeight,
|
||||
settings.normalWeight,
|
||||
settings.normalWeight,
|
||||
settings.normalWeight,
|
||||
settings.colorWeight,
|
||||
settings.colorWeight,
|
||||
settings.colorWeight,
|
||||
];
|
||||
}
|
||||
|
||||
var flags = [];
|
||||
if (settings.lockBorder) {
|
||||
flags.push("LockBorder");
|
||||
flags.push('LockBorder');
|
||||
}
|
||||
|
||||
var threshold = Math.pow(10, -settings.errorThresholdLog10);
|
||||
var stride = (geo.attributes.position instanceof THREE.InterleavedBufferAttribute) ? geo.attributes.position.data.stride : 3;
|
||||
var stride = geo.attributes.position instanceof THREE.InterleavedBufferAttribute ? geo.attributes.position.data.stride : 3;
|
||||
|
||||
console.time('simplify');
|
||||
|
||||
var res =
|
||||
settings.useAttributes
|
||||
? MeshoptSimplifier.simplifyWithAttributes(indices, positions, stride, attrib, attributes, attrib_weights, null, target, threshold, flags)
|
||||
var res = settings.useAttributes
|
||||
? MeshoptSimplifier.simplifyWithAttributes(
|
||||
indices,
|
||||
positions,
|
||||
stride,
|
||||
attrib,
|
||||
attributes,
|
||||
attrib_weights,
|
||||
null,
|
||||
target,
|
||||
threshold,
|
||||
flags,
|
||||
)
|
||||
: MeshoptSimplifier.simplify(indices, positions, stride, target, threshold, flags);
|
||||
|
||||
console.timeEnd('simplify');
|
||||
@@ -174,8 +192,11 @@
|
||||
colors = new Float32Array(geo.attributes.color.array);
|
||||
}
|
||||
|
||||
var pos_stride = (geo.attributes.position instanceof THREE.InterleavedBufferAttribute) ? geo.attributes.position.data.stride : 3;
|
||||
var col_stride = (geo.attributes.color instanceof THREE.InterleavedBufferAttribute) ? geo.attributes.color.data.stride : geo.attributes.color.itemSize;
|
||||
var pos_stride = geo.attributes.position instanceof THREE.InterleavedBufferAttribute ? geo.attributes.position.data.stride : 3;
|
||||
var col_stride =
|
||||
geo.attributes.color instanceof THREE.InterleavedBufferAttribute
|
||||
? geo.attributes.color.data.stride
|
||||
: geo.attributes.color.itemSize;
|
||||
|
||||
// note: we are converting source color array without normalization; if the color data is quantized, we need to divide by 255 to normalize it
|
||||
var colorScale = geo.attributes.color && geo.attributes.color.normalized ? 255 : 1;
|
||||
@@ -191,11 +212,10 @@
|
||||
geo.index = new THREE.BufferAttribute(res, 1);
|
||||
}
|
||||
|
||||
function simplify()
|
||||
{
|
||||
function simplify() {
|
||||
MeshoptSimplifier.useExperimentalFeatures = true;
|
||||
|
||||
MeshoptSimplifier.ready.then(function() {
|
||||
MeshoptSimplifier.ready.then(function () {
|
||||
scene.traverse(function (object) {
|
||||
if (object.isMesh) {
|
||||
simplifyMesh(object.geometry);
|
||||
@@ -207,21 +227,19 @@
|
||||
});
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
function reload() {
|
||||
var simp = import('/js/meshopt_simplifier.module.js?x=' + Date.now());
|
||||
MeshoptSimplifier.ready = simp.then(function (s) {
|
||||
return s.MeshoptSimplifier.ready.then(function () {
|
||||
for (var prop in s.MeshoptSimplifier) {
|
||||
MeshoptSimplifier[prop] = s.MeshoptSimplifier[prop];
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
scene.traverse(function(child) {
|
||||
function update() {
|
||||
scene.traverse(function (child) {
|
||||
if (child.isMesh) {
|
||||
child.material.wireframe = settings.wireframe;
|
||||
}
|
||||
@@ -231,8 +249,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function load(path)
|
||||
{
|
||||
function load(path) {
|
||||
if (model) {
|
||||
scene.remove(model);
|
||||
model = undefined;
|
||||
@@ -245,28 +262,32 @@
|
||||
|
||||
var loader = new GLTFLoader();
|
||||
loader.setMeshoptDecoder(MeshoptDecoder);
|
||||
loader.load(path, function (gltf) {
|
||||
model = gltf.scene;
|
||||
loader.load(
|
||||
path,
|
||||
function (gltf) {
|
||||
model = gltf.scene;
|
||||
|
||||
var bbox = new THREE.Box3().setFromObject(model);
|
||||
var scale = 2 / (bbox.max.y - bbox.min.y);
|
||||
var offset = -(bbox.min.y + bbox.max.y) / 2 * scale;
|
||||
var bbox = new THREE.Box3().setFromObject(model);
|
||||
var scale = 2 / (bbox.max.y - bbox.min.y);
|
||||
var offset = (-(bbox.min.y + bbox.max.y) / 2) * scale;
|
||||
|
||||
model.scale.set(scale, scale, scale);
|
||||
model.position.set(0, offset, 0);
|
||||
model.scale.set(scale, scale, scale);
|
||||
model.position.set(0, offset, 0);
|
||||
|
||||
scene.add(model);
|
||||
scene.add(model);
|
||||
|
||||
mixer = new THREE.AnimationMixer(model);
|
||||
mixer = new THREE.AnimationMixer(model);
|
||||
|
||||
if (gltf.animations.length) {
|
||||
mixer.clipAction(gltf.animations[gltf.animations.length - 1]).play();
|
||||
}
|
||||
}, onProgress, onError);
|
||||
if (gltf.animations.length) {
|
||||
mixer.clipAction(gltf.animations[gltf.animations.length - 1]).play();
|
||||
}
|
||||
},
|
||||
onProgress,
|
||||
onError,
|
||||
);
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
function init() {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
@@ -297,8 +318,7 @@
|
||||
clock = new THREE.Clock();
|
||||
}
|
||||
|
||||
function onWindowResize()
|
||||
{
|
||||
function onWindowResize() {
|
||||
windowHalfX = window.innerWidth / 2;
|
||||
windowHalfY = window.innerHeight / 2;
|
||||
|
||||
@@ -308,8 +328,7 @@
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
}
|
||||
|
||||
function animate()
|
||||
{
|
||||
function animate() {
|
||||
if (mixer) {
|
||||
mixer.update(clock.getDelta());
|
||||
}
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@ var interface = {
|
||||
},
|
||||
};
|
||||
|
||||
gltfpack.pack(args, interface)
|
||||
gltfpack
|
||||
.pack(args, interface)
|
||||
.then(function (log) {
|
||||
process.stdout.write(log);
|
||||
process.exit(0);
|
||||
|
||||
+39
-41
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
function init(wasm) {
|
||||
if (ready) {
|
||||
throw new Error("init must be called once");
|
||||
throw new Error('init must be called once');
|
||||
}
|
||||
|
||||
ready = Promise.resolve(wasm)
|
||||
@@ -35,11 +35,11 @@ function init(wasm) {
|
||||
*/
|
||||
function pack(args, iface) {
|
||||
if (!ready) {
|
||||
throw new Error("init must be called before pack");
|
||||
throw new Error('init must be called before pack');
|
||||
}
|
||||
|
||||
var argv = args.slice();
|
||||
argv.unshift("gltfpack");
|
||||
argv.unshift('gltfpack');
|
||||
|
||||
return ready.then(function () {
|
||||
var buf = uploadArgv(argv);
|
||||
@@ -74,13 +74,12 @@ var instance;
|
||||
var fs_interface;
|
||||
|
||||
var output = { data: new Uint8Array(), position: 0, size: 0 };
|
||||
var fds = { 1: output, 2: output, 3: { mount: "/", path: "/" }, 4: { mount: "/gltfpack-$pwd", path: "" } };
|
||||
var fds = { 1: output, 2: output, 3: { mount: '/', path: '/' }, 4: { mount: '/gltfpack-$pwd', path: '' } };
|
||||
|
||||
var wasi = {
|
||||
proc_exit: function(rval) {
|
||||
},
|
||||
proc_exit: function (rval) {},
|
||||
|
||||
fd_close: function(fd) {
|
||||
fd_close: function (fd) {
|
||||
if (!fds[fd]) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -97,7 +96,7 @@ var wasi = {
|
||||
}
|
||||
},
|
||||
|
||||
fd_fdstat_get: function(fd, stat) {
|
||||
fd_fdstat_get: function (fd, stat) {
|
||||
if (!fds[fd]) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -112,7 +111,7 @@ var wasi = {
|
||||
return 0;
|
||||
},
|
||||
|
||||
path_open32: function(parent_fd, dirflags, path, path_len, oflags, fs_rights_base, fs_rights_inheriting, fdflags, opened_fd) {
|
||||
path_open32: function (parent_fd, dirflags, path, path_len, oflags, fs_rights_base, fs_rights_inheriting, fdflags, opened_fd) {
|
||||
if (!fds[parent_fd] || fds[parent_fd].path === undefined) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -150,7 +149,7 @@ var wasi = {
|
||||
return 0;
|
||||
},
|
||||
|
||||
path_filestat_get: function(parent_fd, flags, path, path_len, buf) {
|
||||
path_filestat_get: function (parent_fd, flags, path, path_len, buf) {
|
||||
if (!fds[parent_fd] || fds[parent_fd].path === undefined) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -159,14 +158,13 @@ var wasi = {
|
||||
var name = getString(heap.buffer, path, path_len);
|
||||
|
||||
var heap = getHeap();
|
||||
for (var i = 0; i < 64; ++i)
|
||||
heap.setUint8(buf + i, 0);
|
||||
for (var i = 0; i < 64; ++i) heap.setUint8(buf + i, 0);
|
||||
|
||||
heap.setUint8(buf + 16, name == "." ? 3 : 4);
|
||||
heap.setUint8(buf + 16, name == '.' ? 3 : 4);
|
||||
return 0;
|
||||
},
|
||||
|
||||
fd_prestat_get: function(fd, buf) {
|
||||
fd_prestat_get: function (fd, buf) {
|
||||
if (!fds[fd] || fds[fd].path === undefined) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -179,7 +177,7 @@ var wasi = {
|
||||
return 0;
|
||||
},
|
||||
|
||||
fd_prestat_dir_name: function(fd, path, path_len) {
|
||||
fd_prestat_dir_name: function (fd, path, path_len) {
|
||||
if (!fds[fd] || fds[fd].path === undefined) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -195,15 +193,15 @@ var wasi = {
|
||||
return 0;
|
||||
},
|
||||
|
||||
path_remove_directory: function(parent_fd, path, path_len) {
|
||||
path_remove_directory: function (parent_fd, path, path_len) {
|
||||
return WASI_EINVAL;
|
||||
},
|
||||
|
||||
fd_fdstat_set_flags: function(fd, flags) {
|
||||
fd_fdstat_set_flags: function (fd, flags) {
|
||||
return WASI_ENOSYS;
|
||||
},
|
||||
|
||||
fd_seek32: function(fd, offset, whence, newoffset) {
|
||||
fd_seek32: function (fd, offset, whence, newoffset) {
|
||||
if (!fds[fd]) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -211,20 +209,20 @@ var wasi = {
|
||||
var newposition;
|
||||
|
||||
switch (whence) {
|
||||
case 0:
|
||||
newposition = offset;
|
||||
break;
|
||||
case 0:
|
||||
newposition = offset;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
newposition = fds[fd].position + offset;
|
||||
break;
|
||||
case 1:
|
||||
newposition = fds[fd].position + offset;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
newposition = fds[fd].size;
|
||||
break;
|
||||
case 2:
|
||||
newposition = fds[fd].size;
|
||||
break;
|
||||
|
||||
default:
|
||||
return WASI_EINVAL;
|
||||
default:
|
||||
return WASI_EINVAL;
|
||||
}
|
||||
|
||||
if (newposition > fds[fd].size) {
|
||||
@@ -238,7 +236,7 @@ var wasi = {
|
||||
return 0;
|
||||
},
|
||||
|
||||
fd_read: function(fd, iovs, iovs_len, nread) {
|
||||
fd_read: function (fd, iovs, iovs_len, nread) {
|
||||
if (!fds[fd]) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -262,7 +260,7 @@ var wasi = {
|
||||
return 0;
|
||||
},
|
||||
|
||||
fd_write: function(fd, iovs, iovs_len, nwritten) {
|
||||
fd_write: function (fd, iovs, iovs_len, nwritten) {
|
||||
if (!fds[fd]) {
|
||||
return WASI_EBADF;
|
||||
}
|
||||
@@ -362,13 +360,13 @@ if (typeof window === 'undefined' && typeof process !== 'undefined' && process.r
|
||||
|
||||
// UMD
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.gltfpack = factory();
|
||||
}
|
||||
}(typeof self !== 'undefined' ? self : this, function () {
|
||||
return { init, pack };
|
||||
}));
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.gltfpack = factory();
|
||||
}
|
||||
})(typeof self !== 'undefined' ? self : this, function () {
|
||||
return { init, pack };
|
||||
});
|
||||
|
||||
+26
-29
@@ -2,7 +2,7 @@ var encoder = require('./meshopt_encoder.js');
|
||||
var decoder = require('./meshopt_decoder.js');
|
||||
var { performance } = require('perf_hooks');
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
process.on('unhandledRejection', (error) => {
|
||||
console.log('unhandledRejection', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -12,12 +12,11 @@ function bytes(view) {
|
||||
}
|
||||
|
||||
var tests = {
|
||||
roundtripVertexBuffer: function() {
|
||||
var N = 1024*1024;
|
||||
roundtripVertexBuffer: function () {
|
||||
var N = 1024 * 1024;
|
||||
var data = new Uint8Array(N * 16);
|
||||
|
||||
for (var i = 0; i < N * 16; i += 4)
|
||||
{
|
||||
for (var i = 0; i < N * 16; i += 4) {
|
||||
data[i + 0] = 0;
|
||||
data[i + 1] = (i % 16) * 1;
|
||||
data[i + 2] = (i % 16) * 2;
|
||||
@@ -35,12 +34,11 @@ var tests = {
|
||||
return { encodeVertex: t1 - t0, decodeVertex: t2 - t1, bytes: N * 16 };
|
||||
},
|
||||
|
||||
roundtripIndexBuffer: function() {
|
||||
var N = 1024*1024;
|
||||
roundtripIndexBuffer: function () {
|
||||
var N = 1024 * 1024;
|
||||
var data = new Uint32Array(N * 3);
|
||||
|
||||
for (var i = 0; i < N * 3; i += 6)
|
||||
{
|
||||
for (var i = 0; i < N * 3; i += 6) {
|
||||
var v = i / 6;
|
||||
|
||||
data[i + 0] = v;
|
||||
@@ -63,12 +61,11 @@ var tests = {
|
||||
return { encodeIndex: t1 - t0, decodeIndex: t2 - t1, bytes: N * 12 };
|
||||
},
|
||||
|
||||
decodeGltf: function() {
|
||||
var N = 1024*1024;
|
||||
decodeGltf: function () {
|
||||
var N = 1024 * 1024;
|
||||
var data = new Uint8Array(N * 16);
|
||||
|
||||
for (var i = 0; i < N * 16; i += 4)
|
||||
{
|
||||
for (var i = 0; i < N * 16; i += 4) {
|
||||
data[i + 0] = 0;
|
||||
data[i + 1] = (i % 16) * 1;
|
||||
data[i + 2] = (i % 16) * 2;
|
||||
@@ -78,21 +75,21 @@ var tests = {
|
||||
var decoded = new Uint8Array(N * 16);
|
||||
|
||||
var filters = [
|
||||
{ name: "none", filter: "NONE", stride: 16 },
|
||||
{ name: "oct4", filter: "OCTAHEDRAL", stride: 4 },
|
||||
{ name: "oct12", filter: "OCTAHEDRAL", stride: 8 },
|
||||
{ name: "quat12", filter: "QUATERNION", stride: 8 },
|
||||
{ name: "exp", filter: "EXPONENTIAL", stride: 16 },
|
||||
];
|
||||
{ name: 'none', filter: 'NONE', stride: 16 },
|
||||
{ name: 'oct4', filter: 'OCTAHEDRAL', stride: 4 },
|
||||
{ name: 'oct12', filter: 'OCTAHEDRAL', stride: 8 },
|
||||
{ name: 'quat12', filter: 'QUATERNION', stride: 8 },
|
||||
{ name: 'exp', filter: 'EXPONENTIAL', stride: 16 },
|
||||
];
|
||||
|
||||
var results = { bytes: N * 16 };
|
||||
|
||||
for (var i = 0; i < filters.length; ++i) {
|
||||
var f = filters[i];
|
||||
var encoded = encoder.encodeVertexBuffer(data, N * 16 / f.stride, f.stride);
|
||||
var encoded = encoder.encodeVertexBuffer(data, (N * 16) / f.stride, f.stride);
|
||||
|
||||
var t0 = performance.now();
|
||||
decoder.decodeGltfBuffer(decoded, N * 16 / f.stride, f.stride, encoded, "ATTRIBUTES", f.filter);
|
||||
decoder.decodeGltfBuffer(decoded, (N * 16) / f.stride, f.stride, encoded, 'ATTRIBUTES', f.filter);
|
||||
var t1 = performance.now();
|
||||
|
||||
results[f.name] = t1 - t0;
|
||||
@@ -104,7 +101,7 @@ var tests = {
|
||||
|
||||
Promise.all([encoder.ready, decoder.ready]).then(() => {
|
||||
var reps = 10;
|
||||
var data = {}
|
||||
var data = {};
|
||||
|
||||
for (var key in tests) {
|
||||
data[key] = tests[key]();
|
||||
@@ -123,17 +120,17 @@ Promise.all([encoder.ready, decoder.ready]).then(() => {
|
||||
|
||||
for (var key in tests) {
|
||||
var rep = key;
|
||||
rep += ":\n";
|
||||
rep += ':\n';
|
||||
|
||||
for (var idx in data[key]) {
|
||||
if (idx != "bytes") {
|
||||
if (idx != 'bytes') {
|
||||
rep += idx;
|
||||
rep += " ";
|
||||
rep += ' ';
|
||||
rep += data[key][idx];
|
||||
rep += " ms (";
|
||||
rep += data[key].bytes / 1024 / 1024 / 1024 / data[key][idx] * 1000;
|
||||
rep += " GB/s)";
|
||||
rep += "\n";
|
||||
rep += ' ms (';
|
||||
rep += (data[key].bytes / 1024 / 1024 / 1024 / data[key][idx]) * 1000;
|
||||
rep += ' GB/s)';
|
||||
rep += '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ const MeshoptEncoder = require('./meshopt_encoder.js');
|
||||
const MeshoptDecoder = require('./meshopt_decoder.js');
|
||||
const MeshoptSimplifier = require('./meshopt_simplifier.js');
|
||||
|
||||
module.exports = {MeshoptEncoder, MeshoptDecoder, MeshoptSimplifier};
|
||||
module.exports = { MeshoptEncoder, MeshoptDecoder, MeshoptSimplifier };
|
||||
|
||||
+55
-46
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+84
-143
@@ -1,27 +1,23 @@
|
||||
var assert = require('assert').strict;
|
||||
var decoder = require('./meshopt_decoder.js');
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
process.on('unhandledRejection', (error) => {
|
||||
console.log('unhandledRejection', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
var tests = {
|
||||
decodeVertexBuffer: function() {
|
||||
decodeVertexBuffer: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00,
|
||||
0x00, 0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00,
|
||||
0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0,
|
||||
0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1,
|
||||
44, 1, 44, 1, 0, 0, 0, 0, 244, 1, 244, 1
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 44, 1, 44, 1, 0, 0, 0,
|
||||
0, 244, 1, 244, 1,
|
||||
]);
|
||||
|
||||
var result = new Uint8Array(expected.length);
|
||||
@@ -30,20 +26,16 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeVertexBuffer_More: function() {
|
||||
decodeVertexBuffer_More: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x00, 0x01, 0x2a, 0xaa, 0xaa, 0xaa, 0x02, 0x04, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
|
||||
0x44, 0x03, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
|
||||
0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xa0, 0x00, 0x01, 0x2a, 0xaa, 0xaa, 0xaa, 0x02, 0x04, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x03, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10,
|
||||
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 1, 2, 8, 0, 2, 4, 16, 0, 3, 6, 24,
|
||||
0, 4, 8, 32, 0, 5, 10, 40, 0, 6, 12, 48, 0, 7, 14, 56,
|
||||
0, 8, 16, 64, 0, 9, 18, 72, 0, 10, 20, 80, 0, 11, 22, 88,
|
||||
0, 12, 24, 96, 0, 13, 26, 104, 0, 14, 28, 112, 0, 15, 30, 120
|
||||
0, 0, 0, 0, 0, 1, 2, 8, 0, 2, 4, 16, 0, 3, 6, 24, 0, 4, 8, 32, 0, 5, 10, 40, 0, 6, 12, 48, 0, 7, 14, 56, 0, 8, 16, 64, 0, 9, 18, 72, 0,
|
||||
10, 20, 80, 0, 11, 22, 88, 0, 12, 24, 96, 0, 13, 26, 104, 0, 14, 28, 112, 0, 15, 30, 120,
|
||||
]);
|
||||
|
||||
var result = new Uint8Array(expected.length);
|
||||
@@ -52,20 +44,16 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeVertexBuffer_Mode2: function() {
|
||||
decodeVertexBuffer_Mode2: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x02, 0x08, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x02, 0x0a, 0xaa, 0xaa, 0xaa,
|
||||
0xaa, 0xaa, 0xaa, 0xaa, 0x02, 0x0c, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x02, 0x0e,
|
||||
0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xa0, 0x02, 0x08, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x02, 0x0a, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x02, 0x0c, 0xcc, 0xcc,
|
||||
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x02, 0x0e, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0, 0, 0, 0, 4, 5, 6, 7, 8, 10, 12, 14, 12, 15, 18, 21,
|
||||
16, 20, 24, 28, 20, 25, 30, 35, 24, 30, 36, 42, 28, 35, 42, 49,
|
||||
32, 40, 48, 56, 36, 45, 54, 63, 40, 50, 60, 70, 44, 55, 66, 77,
|
||||
48, 60, 72, 84, 52, 65, 78, 91, 56, 70, 84, 98, 60, 75, 90, 105
|
||||
0, 0, 0, 0, 4, 5, 6, 7, 8, 10, 12, 14, 12, 15, 18, 21, 16, 20, 24, 28, 20, 25, 30, 35, 24, 30, 36, 42, 28, 35, 42, 49, 32, 40, 48, 56, 36,
|
||||
45, 54, 63, 40, 50, 60, 70, 44, 55, 66, 77, 48, 60, 72, 84, 52, 65, 78, 91, 56, 70, 84, 98, 60, 75, 90, 105,
|
||||
]);
|
||||
|
||||
var result = new Uint8Array(expected.length);
|
||||
@@ -74,15 +62,13 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeIndexBuffer16: function() {
|
||||
decodeIndexBuffer16: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xe0, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67,
|
||||
0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98, 0x01, 0x69, 0x00, 0x00,
|
||||
0xe0, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98,
|
||||
0x01, 0x69, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint16Array([
|
||||
0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9
|
||||
]);
|
||||
var expected = new Uint16Array([0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9]);
|
||||
|
||||
var result = new Uint16Array(expected.length);
|
||||
decoder.decodeIndexBuffer(new Uint8Array(result.buffer), 12, 2, encoded);
|
||||
@@ -90,15 +76,13 @@ var tests = {
|
||||
assert.deepEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeIndexBuffer32: function() {
|
||||
decodeIndexBuffer32: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xe0, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67,
|
||||
0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98, 0x01, 0x69, 0x00, 0x00,
|
||||
0xe0, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98,
|
||||
0x01, 0x69, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9]);
|
||||
|
||||
var result = new Uint32Array(expected.length);
|
||||
decoder.decodeIndexBuffer(new Uint8Array(result.buffer), 12, 4, encoded);
|
||||
@@ -106,15 +90,13 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeIndexBufferV1: function() {
|
||||
decodeIndexBufferV1: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xe1, 0xf0, 0x10, 0xfe, 0x1f, 0x3d, 0x00, 0x0a, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86,
|
||||
0x65, 0x89, 0x68, 0x98, 0x01, 0x69, 0x00, 0x00,
|
||||
0xe1, 0xf0, 0x10, 0xfe, 0x1f, 0x3d, 0x00, 0x0a, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98, 0x01, 0x69, 0x00,
|
||||
0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 2, 2, 1, 3, 0, 1, 2, 2, 1, 5, 2, 1, 4
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 2, 2, 1, 3, 0, 1, 2, 2, 1, 5, 2, 1, 4]);
|
||||
|
||||
var result = new Uint32Array(expected.length);
|
||||
decoder.decodeIndexBuffer(new Uint8Array(result.buffer), 15, 4, encoded);
|
||||
@@ -122,15 +104,13 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeIndexBufferV1_More: function() {
|
||||
decodeIndexBufferV1_More: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xe1, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67,
|
||||
0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98, 0x01, 0x69, 0x00, 0x00,
|
||||
0xe1, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98,
|
||||
0x01, 0x69, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9]);
|
||||
|
||||
var result = new Uint32Array(expected.length);
|
||||
decoder.decodeIndexBuffer(new Uint8Array(result.buffer), 12, 4, encoded);
|
||||
@@ -138,14 +118,11 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeIndexBufferV1_3Edges: function() {
|
||||
decodeIndexBufferV1_3Edges: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xe1, 0xf0, 0x20, 0x30, 0x40, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89,
|
||||
0x68, 0x98, 0x01, 0x69, 0x00, 0x00,
|
||||
]);
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 2, 1, 0, 3, 2, 1, 4, 0, 2, 5
|
||||
0xe1, 0xf0, 0x20, 0x30, 0x40, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98, 0x01, 0x69, 0x00, 0x00,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 2, 1, 0, 3, 2, 1, 4, 0, 2, 5]);
|
||||
|
||||
var result = new Uint32Array(expected.length);
|
||||
decoder.decodeIndexBuffer(new Uint8Array(result.buffer), 12, 4, encoded);
|
||||
@@ -153,14 +130,10 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeIndexSequence: function() {
|
||||
var encoded = new Uint8Array([
|
||||
0xd1, 0x00, 0x04, 0xcd, 0x01, 0x04, 0x07, 0x98, 0x1f, 0x00, 0x00, 0x00, 0x00,
|
||||
]);
|
||||
decodeIndexSequence: function () {
|
||||
var encoded = new Uint8Array([0xd1, 0x00, 0x04, 0xcd, 0x01, 0x04, 0x07, 0x98, 0x1f, 0x00, 0x00, 0x00, 0x00]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 51, 2, 49, 1000
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 51, 2, 49, 1000]);
|
||||
|
||||
var result = new Uint32Array(expected.length);
|
||||
decoder.decodeIndexSequence(new Uint8Array(result.buffer), 6, 4, encoded);
|
||||
@@ -168,132 +141,100 @@ var tests = {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeFilterOct8: function() {
|
||||
decodeFilterOct8: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x8b, 0x8c, 0xfd, 0x00,
|
||||
0x01, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x7f, 0x00,
|
||||
0xa0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x1e, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x8b, 0x8c, 0xfd, 0x00, 0x01, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x7f, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0, 1, 127, 0,
|
||||
0, 159, 82, 1,
|
||||
255, 1, 127, 0,
|
||||
1, 130, 241, 1,
|
||||
]);
|
||||
var expected = new Uint8Array([0, 1, 127, 0, 0, 159, 82, 1, 255, 1, 127, 0, 1, 130, 241, 1]);
|
||||
|
||||
var result = new Uint8Array(expected.length);
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 4, 4, encoded, /* filter= */ "OCTAHEDRAL");
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 4, 4, encoded, /* filter= */ 'OCTAHEDRAL');
|
||||
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeFilterOct12: function() {
|
||||
decodeFilterOct12: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x3d, 0x5a, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x01,
|
||||
0x3f, 0x00, 0x00, 0x00, 0x9a, 0x99, 0x26, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x0a, 0x00,
|
||||
0x00, 0x01, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0xff, 0x07, 0x00, 0x00,
|
||||
0xa0, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x3d, 0x5a, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x9a, 0x99, 0x26,
|
||||
0x01, 0x3f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x0a, 0x00, 0x00, 0x01, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff, 0x07,
|
||||
0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint16Array([
|
||||
0, 16, 32767, 0,
|
||||
0, 32621, 3088, 1,
|
||||
32764, 16, 471, 0,
|
||||
307, 28541, 16093, 1,
|
||||
]);
|
||||
var expected = new Uint16Array([0, 16, 32767, 0, 0, 32621, 3088, 1, 32764, 16, 471, 0, 307, 28541, 16093, 1]);
|
||||
|
||||
var result = new Uint16Array(expected.length);
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 4, 8, encoded, /* filter= */ "OCTAHEDRAL");
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 4, 8, encoded, /* filter= */ 'OCTAHEDRAL');
|
||||
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeFilterQuat12: function() {
|
||||
decodeFilterQuat12: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x3d, 0x5a, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x01,
|
||||
0x3f, 0x00, 0x00, 0x00, 0x9a, 0x99, 0x26, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x0a, 0x00,
|
||||
0x00, 0x01, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0xfc, 0x07,
|
||||
0xa0, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x3d, 0x5a, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x9a, 0x99, 0x26,
|
||||
0x01, 0x3f, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x0a, 0x00, 0x00, 0x01, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xfc, 0x07,
|
||||
]);
|
||||
|
||||
var expected = new Uint16Array([
|
||||
32767, 0, 11, 0,
|
||||
0, 25013, 0, 21166,
|
||||
11, 0, 23504, 22830,
|
||||
158, 14715, 0, 29277,
|
||||
]);
|
||||
var expected = new Uint16Array([32767, 0, 11, 0, 0, 25013, 0, 21166, 11, 0, 23504, 22830, 158, 14715, 0, 29277]);
|
||||
|
||||
var result = new Uint16Array(expected.length);
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 4, 8, encoded, /* filter= */ "QUATERNION");
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 4, 8, encoded, /* filter= */ 'QUATERNION');
|
||||
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeFilterExp: function() {
|
||||
decodeFilterExp: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xff, 0xf7, 0xff, 0xff, 0x02, 0xff, 0xff, 0x7f,
|
||||
0xfe,
|
||||
0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xff, 0xf7, 0xff, 0xff, 0x02, 0xff,
|
||||
0xff, 0x7f, 0xfe,
|
||||
]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0,
|
||||
0x3fc00000,
|
||||
0xc2100000,
|
||||
0x49fffffe,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 0x3fc00000, 0xc2100000, 0x49fffffe]);
|
||||
|
||||
var result = new Uint32Array(expected.length);
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 1, 16, encoded, /* filter= */ "EXPONENTIAL");
|
||||
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 1, 16, encoded, /* filter= */ 'EXPONENTIAL');
|
||||
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeGltfBuffer: function() {
|
||||
decodeGltfBuffer: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00,
|
||||
0x00, 0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00,
|
||||
0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0,
|
||||
0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1,
|
||||
44, 1, 44, 1, 0, 0, 0, 0, 244, 1, 244, 1
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 44, 1, 44, 1, 0, 0, 0,
|
||||
0, 244, 1, 244, 1,
|
||||
]);
|
||||
|
||||
var result = new Uint8Array(expected.length);
|
||||
decoder.decodeGltfBuffer(result, 4, 12, encoded, /* mode= */ "ATTRIBUTES");
|
||||
decoder.decodeGltfBuffer(result, 4, 12, encoded, /* mode= */ 'ATTRIBUTES');
|
||||
assert.deepStrictEqual(result, expected);
|
||||
},
|
||||
|
||||
decodeGltfBufferAsync: function() {
|
||||
decodeGltfBufferAsync: function () {
|
||||
var encoded = new Uint8Array([
|
||||
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00,
|
||||
0x00, 0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00,
|
||||
0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0,
|
||||
0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1,
|
||||
44, 1, 44, 1, 0, 0, 0, 0, 244, 1, 244, 1
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 44, 1, 44, 1, 0, 0, 0,
|
||||
0, 244, 1, 244, 1,
|
||||
]);
|
||||
|
||||
decoder.decodeGltfBufferAsync(4, 12, encoded, /* mode= */ "ATTRIBUTES").then(function (result) {
|
||||
decoder.decodeGltfBufferAsync(4, 12, encoded, /* mode= */ 'ATTRIBUTES').then(function (result) {
|
||||
assert.deepStrictEqual(result, expected);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -11,18 +11,18 @@ MeshoptDecoder.ready = Promise.resolve();
|
||||
|
||||
function assert(cond) {
|
||||
if (!cond) {
|
||||
throw new Error("Assertion failed");
|
||||
throw new Error('Assertion failed');
|
||||
}
|
||||
}
|
||||
|
||||
function dezig(v) {
|
||||
return ((v & 1) !== 0) ? ~(v >>> 1) : v >>> 1;
|
||||
return (v & 1) !== 0 ? ~(v >>> 1) : v >>> 1;
|
||||
}
|
||||
|
||||
MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, filter) => {
|
||||
assert(source[0] === 0xA0);
|
||||
assert(source[0] === 0xa0);
|
||||
|
||||
const maxBlockElements = Math.min((0x2000 / byteStride) & ~0x000F, 0x100);
|
||||
const maxBlockElements = Math.min((0x2000 / byteStride) & ~0x000f, 0x100);
|
||||
|
||||
const deltas = new Uint8Array(0x10);
|
||||
|
||||
@@ -36,7 +36,7 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
// Attribute Blocks
|
||||
for (let dstElemBase = 0; dstElemBase < elementCount; dstElemBase += maxBlockElements) {
|
||||
const attrBlockElementCount = Math.min(elementCount - dstElemBase, maxBlockElements);
|
||||
const groupCount = ((attrBlockElementCount + 0x0F) & ~0x0F) >>> 4;
|
||||
const groupCount = ((attrBlockElementCount + 0x0f) & ~0x0f) >>> 4;
|
||||
const headerByteCount = ((groupCount + 0x03) & ~0x03) >>> 2;
|
||||
|
||||
// Data blocks
|
||||
@@ -47,8 +47,7 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
for (let group = 0; group < groupCount; group++) {
|
||||
const mode = (source[headerBitsOffs] >>> ((group & 0x03) << 1)) & 0x03;
|
||||
// If this is the last group, move to the next byte of header bits.
|
||||
if ((group & 0x03) === 0x03)
|
||||
headerBitsOffs++;
|
||||
if ((group & 0x03) === 0x03) headerBitsOffs++;
|
||||
|
||||
const dstElemGroup = dstElemBase + (group << 4);
|
||||
|
||||
@@ -61,10 +60,9 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
srcOffs += 0x04;
|
||||
for (let m = 0; m < 0x10; m++) {
|
||||
// 0 = >>> 6, 1 = >>> 4, 2 = >>> 2, 3 = >>> 0
|
||||
const shift = (6 - ((m & 0x03) << 1));
|
||||
const shift = 6 - ((m & 0x03) << 1);
|
||||
let delta = (source[srcBase + (m >>> 2)] >>> shift) & 0x03;
|
||||
if (delta === 3)
|
||||
delta = source[srcOffs++];
|
||||
if (delta === 3) delta = source[srcOffs++];
|
||||
deltas[m] = delta;
|
||||
}
|
||||
} else if (mode === 2) {
|
||||
@@ -73,10 +71,9 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
srcOffs += 0x08;
|
||||
for (let m = 0; m < 0x10; m++) {
|
||||
// 0 = >>> 6, 1 = >>> 4, 2 = >>> 2, 3 = >>> 0
|
||||
const shift = (m & 0x01) ? 0 : 4;
|
||||
const shift = m & 0x01 ? 0 : 4;
|
||||
let delta = (source[srcBase + (m >>> 1)] >>> shift) & 0x0f;
|
||||
if (delta === 0xf)
|
||||
delta = source[srcOffs++];
|
||||
if (delta === 0xf) delta = source[srcOffs++];
|
||||
deltas[m] = delta;
|
||||
}
|
||||
} else {
|
||||
@@ -88,12 +85,11 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
// Go through and apply deltas to data
|
||||
for (let m = 0; m < 0x10; m++) {
|
||||
const dstElem = dstElemGroup + m;
|
||||
if (dstElem >= elementCount)
|
||||
break;
|
||||
if (dstElem >= elementCount) break;
|
||||
|
||||
const delta = dezig(deltas[m]);
|
||||
const dstOffs = dstElem * byteStride + byte;
|
||||
target[dstOffs] = (tempData[byte] += delta);
|
||||
target[dstOffs] = tempData[byte] += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,13 +109,15 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
}
|
||||
|
||||
for (let i = 0; i < 4 * elementCount; i += 4) {
|
||||
let x = dst[i + 0], y = dst[i + 1], one = dst[i + 2];
|
||||
let x = dst[i + 0],
|
||||
y = dst[i + 1],
|
||||
one = dst[i + 2];
|
||||
x /= one;
|
||||
y /= one;
|
||||
const z = 1.0 - Math.abs(x) - Math.abs(y);
|
||||
const t = Math.max(-z, 0.0);
|
||||
x -= (x >= 0) ? t : -t;
|
||||
y -= (y >= 0) ? t : -t;
|
||||
x -= x >= 0 ? t : -t;
|
||||
y -= y >= 0 ? t : -t;
|
||||
const h = maxInt / Math.hypot(x, y, z);
|
||||
dst[i + 0] = Math.round(x * h);
|
||||
dst[i + 1] = Math.round(y * h);
|
||||
@@ -138,11 +136,11 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
let x = dst[i + 0] * s;
|
||||
let y = dst[i + 1] * s;
|
||||
let z = dst[i + 2] * s;
|
||||
let w = Math.sqrt(Math.max(0.0, 1.0 - x**2 - y**2 - z**2));
|
||||
dst[i + (maxComponent + 1) % 4] = Math.round(x * 32767);
|
||||
dst[i + (maxComponent + 2) % 4] = Math.round(y * 32767);
|
||||
dst[i + (maxComponent + 3) % 4] = Math.round(z * 32767);
|
||||
dst[i + (maxComponent + 0) % 4] = Math.round(w * 32767);
|
||||
let w = Math.sqrt(Math.max(0.0, 1.0 - x ** 2 - y ** 2 - z ** 2));
|
||||
dst[i + ((maxComponent + 1) % 4)] = Math.round(x * 32767);
|
||||
dst[i + ((maxComponent + 2) % 4)] = Math.round(y * 32767);
|
||||
dst[i + ((maxComponent + 3) % 4)] = Math.round(z * 32767);
|
||||
dst[i + ((maxComponent + 0) % 4)] = Math.round(w * 32767);
|
||||
}
|
||||
} else if (filter === 'EXPONENTIAL') {
|
||||
assert((byteStride & 0x03) === 0x00);
|
||||
@@ -150,28 +148,27 @@ MeshoptDecoder.decodeVertexBuffer = (target, elementCount, byteStride, source, f
|
||||
const src = new Int32Array(target.buffer);
|
||||
const dst = new Float32Array(target.buffer);
|
||||
for (let i = 0; i < (byteStride * elementCount) / 4; i++) {
|
||||
const v = src[i], exp = v >> 24, mantissa = (v << 8) >> 8;
|
||||
dst[i] = 2.0**exp * mantissa;
|
||||
const v = src[i],
|
||||
exp = v >> 24,
|
||||
mantissa = (v << 8) >> 8;
|
||||
dst[i] = 2.0 ** exp * mantissa;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function pushfifo(fifo, n) {
|
||||
for (let i = fifo.length - 1; i > 0; i--)
|
||||
fifo[i] = fifo[i - 1];
|
||||
for (let i = fifo.length - 1; i > 0; i--) fifo[i] = fifo[i - 1];
|
||||
fifo[0] = n;
|
||||
}
|
||||
|
||||
MeshoptDecoder.decodeIndexBuffer = (target, count, byteStride, source) => {
|
||||
assert(source[0] === 0xE1);
|
||||
assert(source[0] === 0xe1);
|
||||
assert(count % 3 === 0);
|
||||
assert(byteStride === 2 || byteStride === 4);
|
||||
|
||||
let dst;
|
||||
if (byteStride === 2)
|
||||
dst = new Uint16Array(target.buffer);
|
||||
else
|
||||
dst = new Uint32Array(target.buffer);
|
||||
if (byteStride === 2) dst = new Uint16Array(target.buffer);
|
||||
else dst = new Uint32Array(target.buffer);
|
||||
|
||||
const triCount = count / 3;
|
||||
|
||||
@@ -183,14 +180,14 @@ MeshoptDecoder.decodeIndexBuffer = (target, count, byteStride, source) => {
|
||||
let n = 0;
|
||||
for (let i = 0; ; i += 7) {
|
||||
const b = source[dataOffs++];
|
||||
n |= (b & 0x7F) << i;
|
||||
n |= (b & 0x7f) << i;
|
||||
|
||||
if (b < 0x80)
|
||||
return n;
|
||||
if (b < 0x80) return n;
|
||||
}
|
||||
}
|
||||
|
||||
let next = 0, last = 0;
|
||||
let next = 0,
|
||||
last = 0;
|
||||
const edgefifo = new Uint32Array(32);
|
||||
const vertexfifo = new Uint32Array(16);
|
||||
|
||||
@@ -201,96 +198,91 @@ MeshoptDecoder.decodeIndexBuffer = (target, count, byteStride, source) => {
|
||||
let dstOffs = 0;
|
||||
for (let i = 0; i < triCount; i++) {
|
||||
const code = source[codeOffs++];
|
||||
const b0 = code >>> 4, b1 = code & 0x0F;
|
||||
const b0 = code >>> 4,
|
||||
b1 = code & 0x0f;
|
||||
|
||||
if (b0 < 0x0F) {
|
||||
const a = edgefifo[(b0 << 1) + 0], b = edgefifo[(b0 << 1) + 1];
|
||||
if (b0 < 0x0f) {
|
||||
const a = edgefifo[(b0 << 1) + 0],
|
||||
b = edgefifo[(b0 << 1) + 1];
|
||||
let c = -1;
|
||||
|
||||
if (b1 === 0x00) {
|
||||
c = next++;
|
||||
pushfifo(vertexfifo, c);
|
||||
} else if (b1 < 0x0D) {
|
||||
} else if (b1 < 0x0d) {
|
||||
c = vertexfifo[b1];
|
||||
} else if (b1 === 0x0D) {
|
||||
} else if (b1 === 0x0d) {
|
||||
c = --last;
|
||||
pushfifo(vertexfifo, c);
|
||||
} else if (b1 === 0x0E) {
|
||||
} else if (b1 === 0x0e) {
|
||||
c = ++last;
|
||||
pushfifo(vertexfifo, c);
|
||||
} else if (b1 === 0x0F) {
|
||||
} else if (b1 === 0x0f) {
|
||||
const v = readLEB128();
|
||||
c = decodeIndex(v);
|
||||
pushfifo(vertexfifo, c);
|
||||
}
|
||||
|
||||
// fifo pushes happen backwards
|
||||
pushfifo(edgefifo, b); pushfifo(edgefifo, c);
|
||||
pushfifo(edgefifo, c); pushfifo(edgefifo, a);
|
||||
pushfifo(edgefifo, b);
|
||||
pushfifo(edgefifo, c);
|
||||
pushfifo(edgefifo, c);
|
||||
pushfifo(edgefifo, a);
|
||||
|
||||
dst[dstOffs++] = a;
|
||||
dst[dstOffs++] = b;
|
||||
dst[dstOffs++] = c;
|
||||
} else { // b0 === 0x0F
|
||||
let a = -1, b = -1, c = -1;
|
||||
} else {
|
||||
// b0 === 0x0F
|
||||
let a = -1,
|
||||
b = -1,
|
||||
c = -1;
|
||||
|
||||
if (b1 < 0x0E) {
|
||||
if (b1 < 0x0e) {
|
||||
const e = source[codeauxOffs + b1];
|
||||
const z = e >>> 4, w = e & 0x0F;
|
||||
const z = e >>> 4,
|
||||
w = e & 0x0f;
|
||||
|
||||
a = next++;
|
||||
|
||||
if (z === 0x00)
|
||||
b = next++;
|
||||
else
|
||||
b = vertexfifo[z - 1];
|
||||
if (z === 0x00) b = next++;
|
||||
else b = vertexfifo[z - 1];
|
||||
|
||||
if (w === 0x00)
|
||||
c = next++;
|
||||
else
|
||||
c = vertexfifo[w - 1];
|
||||
if (w === 0x00) c = next++;
|
||||
else c = vertexfifo[w - 1];
|
||||
|
||||
pushfifo(vertexfifo, a);
|
||||
if (z === 0x00)
|
||||
pushfifo(vertexfifo, b);
|
||||
if (w === 0x00)
|
||||
pushfifo(vertexfifo, c);
|
||||
if (z === 0x00) pushfifo(vertexfifo, b);
|
||||
if (w === 0x00) pushfifo(vertexfifo, c);
|
||||
} else {
|
||||
const e = source[dataOffs++];
|
||||
if (e === 0x00)
|
||||
next = 0;
|
||||
if (e === 0x00) next = 0;
|
||||
|
||||
const z = e >>> 4, w = e & 0x0F;
|
||||
const z = e >>> 4,
|
||||
w = e & 0x0f;
|
||||
|
||||
if (b1 === 0x0E)
|
||||
a = next++;
|
||||
else
|
||||
a = decodeIndex(readLEB128());
|
||||
if (b1 === 0x0e) a = next++;
|
||||
else a = decodeIndex(readLEB128());
|
||||
|
||||
if (z === 0x00)
|
||||
b = next++;
|
||||
else if (z === 0x0F)
|
||||
b = decodeIndex(readLEB128());
|
||||
else
|
||||
b = vertexfifo[z - 1];
|
||||
if (z === 0x00) b = next++;
|
||||
else if (z === 0x0f) b = decodeIndex(readLEB128());
|
||||
else b = vertexfifo[z - 1];
|
||||
|
||||
if (w === 0x00)
|
||||
c = next++;
|
||||
else if (w === 0x0F)
|
||||
c = decodeIndex(readLEB128());
|
||||
else
|
||||
c = vertexfifo[w - 1];
|
||||
if (w === 0x00) c = next++;
|
||||
else if (w === 0x0f) c = decodeIndex(readLEB128());
|
||||
else c = vertexfifo[w - 1];
|
||||
|
||||
pushfifo(vertexfifo, a);
|
||||
if (z === 0x00 || z === 0x0F)
|
||||
pushfifo(vertexfifo, b);
|
||||
if (w === 0x00 || w === 0x0F)
|
||||
pushfifo(vertexfifo, c);
|
||||
if (z === 0x00 || z === 0x0f) pushfifo(vertexfifo, b);
|
||||
if (w === 0x00 || w === 0x0f) pushfifo(vertexfifo, c);
|
||||
}
|
||||
|
||||
pushfifo(edgefifo, a); pushfifo(edgefifo, b);
|
||||
pushfifo(edgefifo, b); pushfifo(edgefifo, c);
|
||||
pushfifo(edgefifo, c); pushfifo(edgefifo, a);
|
||||
pushfifo(edgefifo, a);
|
||||
pushfifo(edgefifo, b);
|
||||
pushfifo(edgefifo, b);
|
||||
pushfifo(edgefifo, c);
|
||||
pushfifo(edgefifo, c);
|
||||
pushfifo(edgefifo, a);
|
||||
|
||||
dst[dstOffs++] = a;
|
||||
dst[dstOffs++] = b;
|
||||
@@ -300,14 +292,12 @@ MeshoptDecoder.decodeIndexBuffer = (target, count, byteStride, source) => {
|
||||
};
|
||||
|
||||
MeshoptDecoder.decodeIndexSequence = (target, count, byteStride, source) => {
|
||||
assert(source[0] === 0xD1);
|
||||
assert(source[0] === 0xd1);
|
||||
assert(byteStride === 2 || byteStride === 4);
|
||||
|
||||
let dst;
|
||||
if (byteStride === 2)
|
||||
dst = new Uint16Array(target.buffer);
|
||||
else
|
||||
dst = new Uint32Array(target.buffer);
|
||||
if (byteStride === 2) dst = new Uint16Array(target.buffer);
|
||||
else dst = new Uint32Array(target.buffer);
|
||||
|
||||
let dataOffs = 0x01;
|
||||
|
||||
@@ -315,10 +305,9 @@ MeshoptDecoder.decodeIndexSequence = (target, count, byteStride, source) => {
|
||||
let n = 0;
|
||||
for (let i = 0; ; i += 7) {
|
||||
const b = source[dataOffs++];
|
||||
n |= (b & 0x7F) << i;
|
||||
n |= (b & 0x7f) << i;
|
||||
|
||||
if (b < 0x80)
|
||||
return n;
|
||||
if (b < 0x80) return n;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,9 +315,9 @@ MeshoptDecoder.decodeIndexSequence = (target, count, byteStride, source) => {
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const v = readLEB128();
|
||||
const b = (v & 0x01);
|
||||
const b = v & 0x01;
|
||||
const delta = dezig(v >>> 1);
|
||||
dst[i] = (last[b] += delta);
|
||||
dst[i] = last[b] += delta;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+35
-33
File diff suppressed because one or more lines are too long
Vendored
+7
-1
@@ -15,5 +15,11 @@ export const MeshoptEncoder: {
|
||||
|
||||
encodeFilterOct: (source: Float32Array, count: number, stride: number, bits: number) => Uint8Array;
|
||||
encodeFilterQuat: (source: Float32Array, count: number, stride: number, bits: number) => Uint8Array;
|
||||
encodeFilterExp: (source: Float32Array, count: number, stride: number, bits: number, mode?: "Separate" | "SharedVector" | "SharedComponent") => Uint8Array;
|
||||
encodeFilterExp: (
|
||||
source: Float32Array,
|
||||
count: number,
|
||||
stride: number,
|
||||
bits: number,
|
||||
mode?: 'Separate' | 'SharedVector' | 'SharedComponent',
|
||||
) => Uint8Array;
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
+31
-99
@@ -2,7 +2,7 @@ var assert = require('assert').strict;
|
||||
var encoder = require('./meshopt_encoder.js');
|
||||
var decoder = require('./meshopt_decoder.js');
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
process.on('unhandledRejection', (error) => {
|
||||
console.log('unhandledRejection', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -12,24 +12,12 @@ function bytes(view) {
|
||||
}
|
||||
|
||||
var tests = {
|
||||
reorderMesh: function() {
|
||||
var indices = new Uint32Array([
|
||||
4, 2, 5,
|
||||
3, 1, 4,
|
||||
0, 1, 3,
|
||||
1, 2, 4,
|
||||
]);
|
||||
reorderMesh: function () {
|
||||
var indices = new Uint32Array([4, 2, 5, 3, 1, 4, 0, 1, 3, 1, 2, 4]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 2,
|
||||
3, 1, 0,
|
||||
4, 3, 0,
|
||||
5, 3, 4,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 2, 3, 1, 0, 4, 3, 0, 5, 3, 4]);
|
||||
|
||||
var remap = new Uint32Array([
|
||||
5, 3, 1, 4, 0, 2
|
||||
]);
|
||||
var remap = new Uint32Array([5, 3, 1, 4, 0, 2]);
|
||||
|
||||
var res = encoder.reorderMesh(indices, /* triangles= */ true, /* optsize= */ true);
|
||||
assert.deepEqual(indices, expected);
|
||||
@@ -37,28 +25,20 @@ var tests = {
|
||||
assert.equal(res[1], 6); // unique
|
||||
},
|
||||
|
||||
reorderPoints: function() {
|
||||
var points = new Float32Array([
|
||||
1, 1, 1,
|
||||
11, 11, 11,
|
||||
2, 2, 2,
|
||||
12, 12, 12,
|
||||
]);
|
||||
reorderPoints: function () {
|
||||
var points = new Float32Array([1, 1, 1, 11, 11, 11, 2, 2, 2, 12, 12, 12]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 2, 1, 3
|
||||
]);
|
||||
var expected = new Uint32Array([0, 2, 1, 3]);
|
||||
|
||||
var remap = encoder.reorderPoints(points, 3);
|
||||
assert.deepEqual(remap, expected);
|
||||
},
|
||||
|
||||
roundtripVertexBuffer: function() {
|
||||
roundtripVertexBuffer: function () {
|
||||
var data = new Uint8Array(16 * 4);
|
||||
|
||||
// this tests 0/2/4/8 bit groups in one stream
|
||||
for (var i = 0; i < 16; ++i)
|
||||
{
|
||||
for (var i = 0; i < 16; ++i) {
|
||||
data[i * 4 + 0] = 0;
|
||||
data[i * 4 + 1] = i * 1;
|
||||
data[i * 4 + 2] = i * 2;
|
||||
@@ -72,7 +52,7 @@ var tests = {
|
||||
assert.deepEqual(decoded, data);
|
||||
},
|
||||
|
||||
roundtripIndexBuffer: function() {
|
||||
roundtripIndexBuffer: function () {
|
||||
var data = new Uint32Array([0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9]);
|
||||
|
||||
var encoded = encoder.encodeIndexBuffer(bytes(data), data.length, 4);
|
||||
@@ -82,7 +62,7 @@ var tests = {
|
||||
assert.deepEqual(decoded, data);
|
||||
},
|
||||
|
||||
roundtripIndexBuffer16: function() {
|
||||
roundtripIndexBuffer16: function () {
|
||||
var data = new Uint16Array([0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9]);
|
||||
|
||||
var encoded = encoder.encodeIndexBuffer(bytes(data), data.length, 2);
|
||||
@@ -92,7 +72,7 @@ var tests = {
|
||||
assert.deepEqual(decoded, data);
|
||||
},
|
||||
|
||||
roundtripIndexSequence: function() {
|
||||
roundtripIndexSequence: function () {
|
||||
var data = new Uint32Array([0, 1, 51, 2, 49, 1000]);
|
||||
|
||||
var encoded = encoder.encodeIndexSequence(bytes(data), data.length, 4);
|
||||
@@ -102,7 +82,7 @@ var tests = {
|
||||
assert.deepEqual(decoded, data);
|
||||
},
|
||||
|
||||
roundtripIndexSequence16: function() {
|
||||
roundtripIndexSequence16: function () {
|
||||
var data = new Uint16Array([0, 1, 51, 2, 49, 1000]);
|
||||
|
||||
var encoded = encoder.encodeIndexSequence(bytes(data), data.length, 2);
|
||||
@@ -112,105 +92,57 @@ var tests = {
|
||||
assert.deepEqual(decoded, data);
|
||||
},
|
||||
|
||||
encodeFilterOct8: function() {
|
||||
var data = new Float32Array([
|
||||
1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0.7071068, 0, 0.707168, 1,
|
||||
-0.7071068, 0, -0.707168, 1,
|
||||
]);
|
||||
encodeFilterOct8: function () {
|
||||
var data = new Float32Array([1, 0, 0, 0, 0, -1, 0, 0, 0.7071068, 0, 0.707168, 1, -0.7071068, 0, -0.707168, 1]);
|
||||
|
||||
var expected = new Uint8Array([
|
||||
0x7f, 0, 0x7f, 0,
|
||||
0, 0x81, 0x7f, 0,
|
||||
0x3f, 0, 0x7f, 0x7f,
|
||||
0x81, 0x40, 0x7f, 0x7f,
|
||||
]);
|
||||
var expected = new Uint8Array([0x7f, 0, 0x7f, 0, 0, 0x81, 0x7f, 0, 0x3f, 0, 0x7f, 0x7f, 0x81, 0x40, 0x7f, 0x7f]);
|
||||
|
||||
// 4 vectors, encode each vector into 4 bytes with 8 bits of precision/component
|
||||
var encoded = encoder.encodeFilterOct(data, 4, 4, 8);
|
||||
assert.deepEqual(encoded, expected);
|
||||
},
|
||||
|
||||
encodeFilterOct12: function() {
|
||||
var data = new Float32Array([
|
||||
1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0.7071068, 0, 0.707168, 1,
|
||||
-0.7071068, 0, -0.707168, 1,
|
||||
]);
|
||||
encodeFilterOct12: function () {
|
||||
var data = new Float32Array([1, 0, 0, 0, 0, -1, 0, 0, 0.7071068, 0, 0.707168, 1, -0.7071068, 0, -0.707168, 1]);
|
||||
|
||||
var expected = new Uint16Array([
|
||||
0x7ff, 0, 0x7ff, 0,
|
||||
0x0, 0xf801, 0x7ff, 0,
|
||||
0x3ff, 0, 0x7ff, 0x7fff,
|
||||
0xf801, 0x400, 0x7ff, 0x7fff,
|
||||
]);
|
||||
var expected = new Uint16Array([0x7ff, 0, 0x7ff, 0, 0x0, 0xf801, 0x7ff, 0, 0x3ff, 0, 0x7ff, 0x7fff, 0xf801, 0x400, 0x7ff, 0x7fff]);
|
||||
|
||||
// 4 vectors, encode each vector into 8 bytes with 12 bits of precision/component
|
||||
var encoded = encoder.encodeFilterOct(data, 4, 8, 12);
|
||||
assert.deepEqual(encoded, bytes(expected));
|
||||
},
|
||||
|
||||
encodeFilterQuat12: function() {
|
||||
var data = new Float32Array([
|
||||
1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0.7071068, 0, 0, 0.707168,
|
||||
-0.7071068, 0, 0, -0.707168,
|
||||
]);
|
||||
encodeFilterQuat12: function () {
|
||||
var data = new Float32Array([1, 0, 0, 0, 0, -1, 0, 0, 0.7071068, 0, 0, 0.707168, -0.7071068, 0, 0, -0.707168]);
|
||||
|
||||
var expected = new Uint16Array([
|
||||
0, 0, 0, 0x7fc,
|
||||
0, 0, 0, 0x7fd,
|
||||
0x7ff, 0, 0, 0x7ff,
|
||||
0x7ff, 0, 0, 0x7ff,
|
||||
]);
|
||||
var expected = new Uint16Array([0, 0, 0, 0x7fc, 0, 0, 0, 0x7fd, 0x7ff, 0, 0, 0x7ff, 0x7ff, 0, 0, 0x7ff]);
|
||||
|
||||
// 4 quaternions, encode each quaternion into 8 bytes with 12 bits of precision/component
|
||||
var encoded = encoder.encodeFilterQuat(data, 4, 8, 12);
|
||||
assert.deepEqual(encoded, bytes(expected));
|
||||
},
|
||||
|
||||
encodeFilterExp: function() {
|
||||
var data = new Float32Array([
|
||||
1,
|
||||
-23.4,
|
||||
-0.1,
|
||||
]);
|
||||
encodeFilterExp: function () {
|
||||
var data = new Float32Array([1, -23.4, -0.1]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0xf7000200,
|
||||
0xf7ffd133,
|
||||
0xf7ffffcd,
|
||||
]);
|
||||
var expected = new Uint32Array([0xf7000200, 0xf7ffd133, 0xf7ffffcd]);
|
||||
|
||||
// 1 vector with 3 components (12 bytes), encode each vector into 12 bytes with 15 bits of precision/component
|
||||
var encoded = encoder.encodeFilterExp(data, 1, 12, 15);
|
||||
assert.deepEqual(encoded, bytes(expected));
|
||||
},
|
||||
|
||||
encodeFilterExpMode: function() {
|
||||
var data = new Float32Array([
|
||||
1,
|
||||
-23.4,
|
||||
-0.1,
|
||||
11.0,
|
||||
]);
|
||||
encodeFilterExpMode: function () {
|
||||
var data = new Float32Array([1, -23.4, -0.1, 11.0]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0xf3002000,
|
||||
0xf7ffd133,
|
||||
0xf3fffccd,
|
||||
0xf7001600,
|
||||
]);
|
||||
var expected = new Uint32Array([0xf3002000, 0xf7ffd133, 0xf3fffccd, 0xf7001600]);
|
||||
|
||||
// 2 vectors with 2 components (8 bytes), encode each vector into 8 bytes with 15 bits of precision/component
|
||||
var encoded = encoder.encodeFilterExp(data, 2, 8, 15, "SharedComponent");
|
||||
var encoded = encoder.encodeFilterExp(data, 2, 8, 15, 'SharedComponent');
|
||||
assert.deepEqual(encoded, bytes(expected));
|
||||
},
|
||||
|
||||
encodeGltfBuffer: function() {
|
||||
encodeGltfBuffer: function () {
|
||||
var data = new Uint32Array([0, 1, 2, 2, 1, 3, 4, 6, 5, 7, 8, 9]);
|
||||
|
||||
var encoded = encoder.encodeGltfBuffer(bytes(data), data.length, 4, 'TRIANGLES');
|
||||
|
||||
+140
-39
File diff suppressed because one or more lines are too long
Vendored
+29
-4
@@ -1,6 +1,6 @@
|
||||
// This file is part of meshoptimizer library and is distributed under the terms of MIT License.
|
||||
// Copyright (C) 2016-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||
export type Flags = "LockBorder" | "Sparse" | "ErrorAbsolute";
|
||||
export type Flags = 'LockBorder' | 'Sparse' | 'ErrorAbsolute';
|
||||
|
||||
export const MeshoptSimplifier: {
|
||||
supported: boolean;
|
||||
@@ -10,13 +10,38 @@ export const MeshoptSimplifier: {
|
||||
|
||||
compactMesh: (indices: Uint32Array) => [Uint32Array, number];
|
||||
|
||||
simplify: (indices: Uint32Array, vertex_positions: Float32Array, vertex_positions_stride: number, target_index_count: number, target_error: number, flags?: Flags[]) => [Uint32Array, number];
|
||||
simplify: (
|
||||
indices: Uint32Array,
|
||||
vertex_positions: Float32Array,
|
||||
vertex_positions_stride: number,
|
||||
target_index_count: number,
|
||||
target_error: number,
|
||||
flags?: Flags[],
|
||||
) => [Uint32Array, number];
|
||||
|
||||
// Experimental; requires useExperimentalFeatures to be set to true
|
||||
simplifyWithAttributes: (indices: Uint32Array, vertex_positions: Float32Array, vertex_positions_stride: number, vertex_attributes: Float32Array, vertex_attributes_stride: number, attribute_weights: number[], vertex_lock: boolean[] | null, target_index_count: number, target_error: number, flags?: Flags[]) => [Uint32Array, number];
|
||||
simplifyWithAttributes: (
|
||||
indices: Uint32Array,
|
||||
vertex_positions: Float32Array,
|
||||
vertex_positions_stride: number,
|
||||
vertex_attributes: Float32Array,
|
||||
vertex_attributes_stride: number,
|
||||
attribute_weights: number[],
|
||||
vertex_lock: boolean[] | null,
|
||||
target_index_count: number,
|
||||
target_error: number,
|
||||
flags?: Flags[],
|
||||
) => [Uint32Array, number];
|
||||
|
||||
getScale: (vertex_positions: Float32Array, vertex_positions_stride: number) => number;
|
||||
|
||||
// Experimental; requires useExperimentalFeatures to be set to true
|
||||
simplifyPoints: (vertex_positions: Float32Array, vertex_positions_stride: number, target_vertex_count: number, vertex_colors?: Float32Array, vertex_colors_stride?: number, color_weight?: number) => Uint32Array;
|
||||
simplifyPoints: (
|
||||
vertex_positions: Float32Array,
|
||||
vertex_positions_stride: number,
|
||||
target_vertex_count: number,
|
||||
vertex_colors?: Float32Array,
|
||||
vertex_colors_stride?: number,
|
||||
color_weight?: number,
|
||||
) => Uint32Array;
|
||||
};
|
||||
|
||||
+135
-31
File diff suppressed because one or more lines are too long
+36
-107
@@ -1,7 +1,7 @@
|
||||
var assert = require('assert').strict;
|
||||
var simplifier = require('./meshopt_simplifier.js');
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
process.on('unhandledRejection', (error) => {
|
||||
console.log('unhandledRejection', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -9,22 +9,14 @@ process.on('unhandledRejection', error => {
|
||||
simplifier.useExperimentalFeatures = true;
|
||||
|
||||
var tests = {
|
||||
compactMesh: function() {
|
||||
var indices = new Uint32Array([
|
||||
0, 1, 3,
|
||||
3, 1, 5,
|
||||
]);
|
||||
compactMesh: function () {
|
||||
var indices = new Uint32Array([0, 1, 3, 3, 1, 5]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1, 2,
|
||||
2, 1, 3,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1, 2, 2, 1, 3]);
|
||||
|
||||
var missing = 2**32-1;
|
||||
var missing = 2 ** 32 - 1;
|
||||
|
||||
var remap = new Uint32Array([
|
||||
0, 1, missing, 2, missing, 3
|
||||
]);
|
||||
var remap = new Uint32Array([0, 1, missing, 2, missing, 3]);
|
||||
|
||||
var res = simplifier.compactMesh(indices);
|
||||
assert.deepEqual(indices, expected);
|
||||
@@ -32,112 +24,65 @@ var tests = {
|
||||
assert.equal(res[1], 4); // unique
|
||||
},
|
||||
|
||||
simplify: function() {
|
||||
simplify: function () {
|
||||
// 0
|
||||
// 1 2
|
||||
// 3 4 5
|
||||
var indices = new Uint32Array([
|
||||
0, 2, 1,
|
||||
1, 2, 3,
|
||||
3, 2, 4,
|
||||
2, 5, 4,
|
||||
]);
|
||||
var indices = new Uint32Array([0, 2, 1, 1, 2, 3, 3, 2, 4, 2, 5, 4]);
|
||||
|
||||
var positions = new Float32Array([
|
||||
0, 4, 0,
|
||||
0, 1, 0,
|
||||
2, 2, 0,
|
||||
0, 0, 0,
|
||||
1, 0, 0,
|
||||
4, 0, 0,
|
||||
]);
|
||||
var positions = new Float32Array([0, 4, 0, 0, 1, 0, 2, 2, 0, 0, 0, 0, 1, 0, 0, 4, 0, 0]);
|
||||
|
||||
var res = simplifier.simplify(indices, positions, 3, /* target indices */ 3, /* target error */ 0.01);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 5, 3,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 5, 3]);
|
||||
|
||||
assert.deepEqual(res[0], expected);
|
||||
assert.equal(res[1], 0); // error
|
||||
},
|
||||
|
||||
simplify16: function() {
|
||||
simplify16: function () {
|
||||
// 0
|
||||
// 1 2
|
||||
// 3 4 5
|
||||
var indices = new Uint16Array([
|
||||
0, 2, 1,
|
||||
1, 2, 3,
|
||||
3, 2, 4,
|
||||
2, 5, 4,
|
||||
]);
|
||||
var indices = new Uint16Array([0, 2, 1, 1, 2, 3, 3, 2, 4, 2, 5, 4]);
|
||||
|
||||
var positions = new Float32Array([
|
||||
0, 4, 0,
|
||||
0, 1, 0,
|
||||
2, 2, 0,
|
||||
0, 0, 0,
|
||||
1, 0, 0,
|
||||
4, 0, 0,
|
||||
]);
|
||||
var positions = new Float32Array([0, 4, 0, 0, 1, 0, 2, 2, 0, 0, 0, 0, 1, 0, 0, 4, 0, 0]);
|
||||
|
||||
var res = simplifier.simplify(indices, positions, 3, /* target indices */ 3, /* target error */ 0.01);
|
||||
|
||||
var expected = new Uint16Array([
|
||||
0, 5, 3,
|
||||
]);
|
||||
var expected = new Uint16Array([0, 5, 3]);
|
||||
|
||||
assert.deepEqual(res[0], expected);
|
||||
assert.equal(res[1], 0); // error
|
||||
},
|
||||
|
||||
simplifyLockBorder: function() {
|
||||
simplifyLockBorder: function () {
|
||||
// 0
|
||||
// 1 2
|
||||
// 3 4 5
|
||||
var indices = new Uint32Array([
|
||||
0, 2, 1,
|
||||
1, 2, 3,
|
||||
3, 2, 4,
|
||||
2, 5, 4,
|
||||
]);
|
||||
var indices = new Uint32Array([0, 2, 1, 1, 2, 3, 3, 2, 4, 2, 5, 4]);
|
||||
|
||||
var positions = new Float32Array([
|
||||
0, 2, 0,
|
||||
0, 1, 0,
|
||||
1, 1, 0,
|
||||
0, 0, 0,
|
||||
1, 0, 0,
|
||||
2, 0, 0,
|
||||
]);
|
||||
var positions = new Float32Array([0, 2, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0]);
|
||||
|
||||
var res = simplifier.simplify(indices, positions, 3, /* target indices */ 3, /* target error */ 0.01, ["LockBorder"]);
|
||||
var res = simplifier.simplify(indices, positions, 3, /* target indices */ 3, /* target error */ 0.01, ['LockBorder']);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 2, 1,
|
||||
1, 2, 3,
|
||||
3, 2, 4,
|
||||
2, 5, 4,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 2, 1, 1, 2, 3, 3, 2, 4, 2, 5, 4]);
|
||||
|
||||
assert.deepEqual(res[0], expected);
|
||||
assert.equal(res[1], 0); // error
|
||||
},
|
||||
|
||||
simplifyAttr: function() {
|
||||
simplifyAttr: function () {
|
||||
var vb_pos = new Float32Array(8 * 3 * 3);
|
||||
var vb_att = new Float32Array(8 * 3 * 3);
|
||||
|
||||
for (var y = 0; y < 8; ++y)
|
||||
{
|
||||
for (var y = 0; y < 8; ++y) {
|
||||
// first four rows are a blue gradient, next four rows are a yellow gradient
|
||||
var r = (y < 4) ? 0.8 + y * 0.05 : 0;
|
||||
var g = (y < 4) ? 0.8 + y * 0.05 : 0;
|
||||
var b = (y < 4) ? 0 : 0.8 + (7 - y) * 0.05;
|
||||
var r = y < 4 ? 0.8 + y * 0.05 : 0;
|
||||
var g = y < 4 ? 0.8 + y * 0.05 : 0;
|
||||
var b = y < 4 ? 0 : 0.8 + (7 - y) * 0.05;
|
||||
|
||||
for (var x = 0; x < 3; ++x)
|
||||
{
|
||||
for (var x = 0; x < 3; ++x) {
|
||||
vb_pos[(y * 3 + x) * 3 + 0] = x;
|
||||
vb_pos[(y * 3 + x) * 3 + 1] = y;
|
||||
vb_pos[(y * 3 + x) * 3 + 2] = 0.03 * x;
|
||||
@@ -149,10 +94,8 @@ var tests = {
|
||||
|
||||
var ib = new Uint32Array(7 * 2 * 6);
|
||||
|
||||
for (var y = 0; y < 7; ++y)
|
||||
{
|
||||
for (var x = 0; x < 2; ++x)
|
||||
{
|
||||
for (var y = 0; y < 7; ++y) {
|
||||
for (var x = 0; x < 2; ++x) {
|
||||
ib[(y * 2 + x) * 6 + 0] = (y + 0) * 3 + (x + 0);
|
||||
ib[(y * 2 + x) * 6 + 1] = (y + 0) * 3 + (x + 1);
|
||||
ib[(y * 2 + x) * 6 + 2] = (y + 1) * 3 + (x + 0);
|
||||
@@ -166,38 +109,24 @@ var tests = {
|
||||
|
||||
var res = simplifier.simplifyWithAttributes(ib, vb_pos, 3, vb_att, 3, attr_weights, null, 6 * 3, 1e-2);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 2, 9, 9, 2, 11,
|
||||
9, 11, 12, 12, 11, 14,
|
||||
12, 14, 21, 21, 14, 23,
|
||||
]);
|
||||
var expected = new Uint32Array([0, 2, 9, 9, 2, 11, 9, 11, 12, 12, 11, 14, 12, 14, 21, 21, 14, 23]);
|
||||
|
||||
assert.deepEqual(res[0], expected);
|
||||
},
|
||||
|
||||
getScale: function() {
|
||||
var positions = new Float32Array([
|
||||
0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3
|
||||
]);
|
||||
getScale: function () {
|
||||
var positions = new Float32Array([0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]);
|
||||
|
||||
assert(simplifier.getScale(positions, 3) == 3.0);
|
||||
},
|
||||
|
||||
simplifyPoints: function() {
|
||||
var positions = new Float32Array([
|
||||
0, 0, 0, 100, 0, 0, 100, 1, 1, 110, 0, 0,
|
||||
]);
|
||||
var colors = new Float32Array([
|
||||
1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
]);
|
||||
simplifyPoints: function () {
|
||||
var positions = new Float32Array([0, 0, 0, 100, 0, 0, 100, 1, 1, 110, 0, 0]);
|
||||
var colors = new Float32Array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
|
||||
var expected = new Uint32Array([
|
||||
0, 1
|
||||
]);
|
||||
var expected = new Uint32Array([0, 1]);
|
||||
|
||||
var expectedC = new Uint32Array([
|
||||
0, 2
|
||||
]);
|
||||
var expectedC = new Uint32Array([0, 2]);
|
||||
|
||||
var res = simplifier.simplifyPoints(positions, 3, 2);
|
||||
assert.deepEqual(res, expected);
|
||||
@@ -208,7 +137,7 @@ var tests = {
|
||||
|
||||
var resC2 = simplifier.simplifyPoints(positions, 3, 2, colors, 3, 1e-2);
|
||||
assert.deepEqual(resC2, expected);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Promise.all([simplifier.ready]).then(() => {
|
||||
|
||||
Reference in New Issue
Block a user