Skip to content

Commit

Permalink
tweaked html
Browse files Browse the repository at this point in the history
  • Loading branch information
arcadeperfect committed Nov 27, 2024
1 parent 712f105 commit 47d85ec
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 51 deletions.
105 changes: 105 additions & 0 deletions index copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bevy Vaporwave</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Roboto+Mono&display=swap"
rel="stylesheet">
</head>

<body class="color-scheme-home">

<div class="grid">
<div class="main-column">
<!-- <a href="https://alexharding.ooo" class="back-arrow">alexharding.ooo</a> <a href="https://bsky.app/profile/alexharding.bsky.social" class="back-arrow">bluesky</a> -->
<span class="nav-links">
<a href="https://alexharding.ooo" class="nice-links">alexharding.ooo</a>
&nbsp;&nbsp;&nbsp;
<a href="https://bsky.app/profile/alexharding.bsky.social" class="nice-links">bluesky</a>
</span>
<h1 class="main-heading">Bevy Vaporwave</h1>
<div id="wasm-container"></div>
<br>
<h2><a href="https://github.com/arcadeperfect/bevy_vaporwave">Github</a></h2>
<br>
<p>Side project to learn the basics of wgsl and develop a look for my <a href="https://alexharding.ooo/posts/Rustroneer/">main Bevy project</a>.</p>
<br>
<p>The code is pretty garbage. I doubt I will continue work on this, but I will roll what I learned into the main project and hopefully it will be better that time. If you're intetested though the repo is public.</p>
<br>
<p>Features:</p>
<ul>
<li>Arbitrarily define edges to render, not render every triangle </li>
<li>Varying colors per mesh, no textures</li>
<li>Optionally "Solid" wireframe, ie it occludes its own back faces and objects behind it</li>
<li>Outline for silhouette when visible edges are sparse</li>
<li>Support gltf animation</li>
</ul>
<br>
<p>I developed a simple workflow with Blender which allows you to mark edges for rendering, paint vertex colors and store the data in a custom gltf attribute (see video below). It isn't great but it does the job. The blender files and a python script are in the repo. Bevy then builds a mesh out of line primitives for the wireframe and uses the original mesh for a fill. The mesh is duplicated, dilated along normals and pushed backwards in clip space by a shader to create the outline.</p>
<br>
<p>Issues:</p>
<ul>
<li>Wireframe thickness cannot be set because this is not supported by wgpu line primitives</li>
<li>Clip space method for outline isn't ideal, a stencil buffer approach would be better but I couldn't work out how to do that with wgpu / bevy render pipeline</li>
<li>Assets are post processed in a system triggered by SceneInstanceReady events. Something that ties into Bevy's async asset loading would be much better </li>
<li>The mesh building algorithm is very slow with large meshes</li>
</ul>
<br>
<h2>Blender Workflow</h2>
<div class="video-wrapper">
<iframe
src="https://www.youtube.com/embed/rfDhslnPBpA?si=I2cgElg45rW-49li&autoplay=1&mute=1"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen
></iframe>
</div>
<br>
<br>
<span class="nav-links">
<a href="https://alexharding.ooo" class="nice-links">alexharding.ooo</a>
&nbsp;&nbsp;&nbsp;
<a href="https://bsky.app/profile/alexharding.bsky.social" class="nice-links">bluesky</a>
</span>
<br>
<br>

</div>

</div>
</div>

<script type="module">
import init from './out/bevy_vaporwave.js';

async function run() {
const wasmContainer = document.getElementById('wasm-container');

const observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.tagName === 'CANVAS') {
node.style.width = '100%';
node.style.height = '100%';
wasmContainer.appendChild(node);
observer.disconnect();
}
}
}
});

observer.observe(document.body, { childList: true });

await init();
}

run();
</script>
</body>

</html>
53 changes: 23 additions & 30 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bevy Vaporwave</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Roboto+Mono&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Roboto+Mono&display=swap" rel="stylesheet">
</head>

<body class="color-scheme-home">
<script>
window.addEventListener('DOMContentLoaded', (event) => {
// Find the canvas element created by Bevy
const canvas = document.querySelector('canvas');
if (canvas) {
// Save the original focus method
const originalFocus = canvas.focus.bind(canvas);
// Override the focus method to include preventScroll
canvas.focus = function(options) {
if (!options || typeof options !== 'object') {
options = { preventScroll: true };
} else {
options.preventScroll = true;
}
originalFocus(options);
};
}
});
</script>
<div class="grid">
<div class="main-column">
<!-- <a href="https://alexharding.ooo" class="back-arrow">alexharding.ooo</a> <a href="https://bsky.app/profile/alexharding.bsky.social" class="back-arrow">bluesky</a> -->
<span class="nav-links">
<a href="https://alexharding.ooo" class="nice-links">alexharding.ooo</a>
&nbsp;&nbsp;&nbsp;
<a href="https://bsky.app/profile/alexharding.bsky.social" class="nice-links">bluesky</a>
</span>
<h1 class="main-heading">Bevy Vaporwave</h1>
<div id="wasm-container"></div>
<div id="wasm-container" tabindex="-1"></div>
<br>
<h2><a href="https://github.com/arcadeperfect/bevy_vaporwave">Github</a></h2>
<br>
Expand Down Expand Up @@ -86,22 +64,30 @@ <h2>Blender Workflow</h2>
</span>
<br>
<br>

</div>

</div>
</div>

<script type="module">
import init from './out/bevy_vaporwave.js';

async function run() {
const wasmContainer = document.getElementById('wasm-container');
window.scrollTo(0, 0);

const wasmContainer = document.getElementById('wasm-container');

const observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.tagName === 'CANVAS') {
node.setAttribute('tabindex', '-1');

const originalFocus = node.focus.bind(node);
node.focus = function() {
const scrollPos = window.scrollY;
originalFocus();
requestAnimationFrame(() => window.scrollTo(0, scrollPos));
};

node.style.width = '100%';
node.style.height = '100%';
wasmContainer.appendChild(node);
Expand All @@ -116,8 +102,15 @@ <h2>Blender Workflow</h2>
await init();
}

run();
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}

if (document.readyState === 'complete') {
run();
} else {
window.addEventListener('load', run);
}
</script>
</body>

</html>
Loading

0 comments on commit 47d85ec

Please sign in to comment.