Skip to content

Commit

Permalink
Merge pull request #725 from zeux/jsformat
Browse files Browse the repository at this point in the history
Integrate Prettier for all JS source
  • Loading branch information
zeux authored Jul 22, 2024
2 parents 6f6e143 + ca65efe commit 48f7abf
Show file tree
Hide file tree
Showing 21 changed files with 977 additions and 893 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"useTabs": true,
"tabWidth": 4,
"semi": true,
"singleQuote": true,
"printWidth": 150,
}
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ dev: $(DEMO)
format:
clang-format -i $(LIBRARY_SOURCES) $(DEMO_SOURCES) $(GLTFPACK_SOURCES)

formatjs:
prettier -w js/*.js gltf/*.js demo/*.html js/*.ts

js: js/meshopt_decoder.js js/meshopt_decoder.module.js js/meshopt_encoder.js js/meshopt_encoder.module.js js/meshopt_simplifier.js js/meshopt_simplifier.module.js

symbols: $(BUILD)/amalgamated.so
Expand Down Expand Up @@ -165,7 +168,7 @@ js/meshopt_simplifier.js: build/simplifier.wasm tools/wasmpack.py

js/%.module.js: js/%.js
sed '\#// export!#q' <$< >$@
sed -i "/\"use strict\";/d" $@
sed -i "/use strict.;/d" $@
sed -i "s#// export! \(.*\)#export { \\1 };#" $@

$(DEMO): $(DEMO_OBJECTS) $(LIBRARY)
Expand Down
105 changes: 53 additions & 52 deletions demo/demo.html
Original file line number Diff line number Diff line change
@@ -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>
57 changes: 32 additions & 25 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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/[email protected]/dist/es-module-shims.js"></script>
Expand All @@ -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">
Expand All @@ -55,8 +61,7 @@
init();
animate();

function init()
{
function init() {
container = document.createElement('div');
document.body.appendChild(container);

Expand All @@ -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);
Expand All @@ -108,8 +118,7 @@
clock = new THREE.Clock();
}

function onWindowResize()
{
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;

Expand All @@ -119,8 +128,7 @@
renderer.setSize(window.innerWidth, window.innerHeight);
}

function animate()
{
function animate() {
if (mixer) {
mixer.update(clock.getDelta());
}
Expand All @@ -129,8 +137,7 @@
render();
}

function render()
{
function render() {
renderer.render(scene, camera);
}
</script>
Expand Down
Loading

0 comments on commit 48f7abf

Please sign in to comment.