-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactor to use JS module style - Improved JS interp - Added samples for communicating changes
- Loading branch information
1 parent
3724e43
commit 71db8e2
Showing
7 changed files
with
300 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,13 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:49458/", | ||
"sslPort": 44384 | ||
} | ||
}, | ||
"profiles": { | ||
"WasmTest": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"applicationUrl": "https://localhost:7010;http://localhost:5076", | ||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/debug?browser={browserInspectUri}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | ||
<link rel="modulepreload" href="./main.js" /> | ||
<link rel="modulepreload" href="./dotnet.js" /> | ||
<title>dotnet + WebGL = 💖</title> | ||
<style> | ||
body | ||
{ | ||
margin: 0; | ||
background-color: black; | ||
overflow: hidden; | ||
} | ||
|
||
canvas#canvas | ||
{ | ||
width: 100vw; | ||
height: 100vh; | ||
outline: none; | ||
margin: 0; | ||
position: absolute; | ||
left: 50%; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
|
||
@media (min-aspect-ratio: 16/9) | ||
{ | ||
canvas#canvas | ||
{ | ||
height: 100vh; | ||
width: calc(100vh * (16 / 9)); | ||
} | ||
} | ||
|
||
@media (max-aspect-ratio: 4/3) | ||
{ | ||
canvas#canvas | ||
{ | ||
width: 100vw; | ||
height: calc(100vw / (4 / 3)); | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<canvas id="canvas" width="16" height="9"> | ||
</canvas> | ||
|
||
<script type="module" src="./main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { dotnet } from './dotnet.js' | ||
|
||
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet | ||
.withDiagnosticTracing(false) | ||
.withApplicationArgumentsFromQuery() | ||
.create(); | ||
|
||
const config = getConfig(); | ||
const exports = await getAssemblyExports(config.mainAssemblyName); | ||
const interop = exports.WasmTest.Interop; | ||
|
||
var canvas = globalThis.document.getElementById("canvas"); | ||
dotnet.instance.Module["canvas"] = canvas; | ||
|
||
setModuleImports("main.js", { | ||
initialize: () => { | ||
|
||
var checkCanvasResize = (dispatch) => { | ||
var devicePixelRatio = window.devicePixelRatio || 1.0; | ||
var displayWidth = canvas.clientWidth * devicePixelRatio; | ||
var displayHeight = canvas.clientHeight * devicePixelRatio; | ||
|
||
if (canvas.width != displayWidth || canvas.height != displayHeight) { | ||
canvas.width = displayWidth; | ||
canvas.height = displayHeight; | ||
dispatch = true; | ||
} | ||
|
||
if (dispatch) | ||
interop.OnCanvasResize(displayWidth, displayHeight, devicePixelRatio); | ||
} | ||
|
||
function checkCanvasResizeFrame() { | ||
checkCanvasResize(false); | ||
requestAnimationFrame(checkCanvasResizeFrame); | ||
} | ||
|
||
var keyDown = (e) => { | ||
e.stopPropagation(); | ||
var shift = e.shiftKey; | ||
var ctrl = e.ctrlKey; | ||
var alt = e.altKey; | ||
var repeat = e.repeat; | ||
var code = e.keyCode; | ||
|
||
interop.OnKeyDown(shift, ctrl, alt, repeat, code); | ||
} | ||
|
||
var keyUp = (e) => { | ||
e.stopPropagation(); | ||
var shift = e.shiftKey; | ||
var ctrl = e.ctrlKey; | ||
var alt = e.altKey; | ||
var code = e.keyCode; | ||
|
||
interop.OnKeyUp(shift, ctrl, alt, code); | ||
} | ||
|
||
var mouseMove = (e) => { | ||
var x = e.offsetX; | ||
var y = e.offsetY; | ||
interop.OnMouseMove(x, y); | ||
} | ||
|
||
var mouseDown = (e) => { | ||
var shift = e.shiftKey; | ||
var ctrl = e.ctrlKey; | ||
var alt = e.altKey; | ||
var button = e.button; | ||
|
||
interop.OnMouseDown(shift, ctrl, alt, button); | ||
} | ||
|
||
var mouseUp = (e) => { | ||
var shift = e.shiftKey; | ||
var ctrl = e.ctrlKey; | ||
var alt = e.altKey; | ||
var button = e.button; | ||
|
||
interop.OnMouseUp(shift, ctrl, alt, button); | ||
} | ||
|
||
var shouldIgnore = (e) => { | ||
e.preventDefault(); | ||
return e.touches.length > 1 || e.type == "touchend" && e.touches.length > 0; | ||
} | ||
|
||
var touchStart = (e) => { | ||
if (shouldIgnore(e)) | ||
return; | ||
|
||
var shift = e.shiftKey; | ||
var ctrl = e.ctrlKey; | ||
var alt = e.altKey; | ||
var button = 0; | ||
var touch = e.changedTouches[0]; | ||
var bcr = e.target.getBoundingClientRect(); | ||
var x = touch.clientX - bcr.x; | ||
var y = touch.clientY - bcr.y; | ||
|
||
interop.OnMouseMove(x, y); | ||
interop.OnMouseDown(shift, ctrl, alt, button); | ||
} | ||
|
||
var touchMove = (e) => { | ||
if (shouldIgnore(e)) | ||
return; | ||
|
||
var touch = e.changedTouches[0]; | ||
var bcr = e.target.getBoundingClientRect(); | ||
var x = touch.clientX - bcr.x; | ||
var y = touch.clientY - bcr.y; | ||
|
||
interop.OnMouseMove(x, y); | ||
} | ||
|
||
var touchEnd = (e) => { | ||
if (shouldIgnore(e)) | ||
return; | ||
|
||
var shift = e.shiftKey; | ||
var ctrl = e.ctrlKey; | ||
var alt = e.altKey; | ||
var button = 0; | ||
var touch = e.changedTouches[0]; | ||
var bcr = e.target.getBoundingClientRect(); | ||
var x = touch.clientX - bcr.x; | ||
var y = touch.clientY - bcr.y; | ||
|
||
interop.OnMouseMove(x, y); | ||
interop.OnMouseUp(shift, ctrl, alt, button); | ||
} | ||
|
||
//canvas.addEventListener("contextmenu", (e) => e.preventDefault(), false); | ||
canvas.addEventListener("keydown", keyDown, false); | ||
canvas.addEventListener("keyup", keyUp, false); | ||
canvas.addEventListener("mousemove", mouseMove, false); | ||
canvas.addEventListener("mousedown", mouseDown, false); | ||
canvas.addEventListener("mouseup", mouseUp, false); | ||
canvas.addEventListener("touchstart", touchStart, false); | ||
canvas.addEventListener("touchmove", touchMove, false); | ||
canvas.addEventListener("touchend", touchEnd, false); | ||
checkCanvasResize(true); | ||
checkCanvasResizeFrame(); | ||
|
||
canvas.tabIndex = 1000; | ||
|
||
interop.SetRootUri(window.location.toString()); | ||
|
||
var langs = navigator.languages || []; | ||
for (var i = 0; i < langs.length; i++) | ||
interop.AddLocale(langs[i]); | ||
interop.AddLocale(navigator.language); | ||
interop.AddLocale(navigator.userLanguage); | ||
} | ||
}); | ||
|
||
await dotnet.run(); |
Oops, something went wrong.