Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Visualization of mechanical CAD drawings using ...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
[email protected]
November 05, 2019
Technology
4.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Visualization of mechanical CAD drawings using WebAssembly and WebGL - Rust Tokyo 2019
[email protected]
November 05, 2019
More Decks by
[email protected]
See All by
[email protected]
製造業にRAGを導入する開発体制の変遷 / ManuAI1
caddi_eng
1
100
バラバラな見積明細と戦う話 / ManuAI2
caddi_eng
0
100
LLMに図面は読めるか – 製造業の「暗黙知」を突破するコンテキスト設計3つのアプローチ / LLMcontext
caddi_eng
1
210
「定型」を許さない製造業データへの挑戦 高度な絞り込みと意味検索を両立する実践 / ElasticON
caddi_eng
0
260
製造業ドメインにおける LLMプロダクト構築: 複雑な文脈へのアプローチ
caddi_eng
1
800
事業状況で変化する最適解。進化し続ける開発組織とアーキテクチャ
caddi_eng
1
17k
キャディでのApache Iceberg, Trino採用事例 -Apache Iceberg and Trino Usecase in CADDi--
caddi_eng
0
660
製造業の会計システムをDDDで開発した話
caddi_eng
3
2.4k
【CADDI VIETNAM】Company Deck for Engineers
caddi_eng
0
2.3k
Other Decks in Technology
See All in Technology
SREとQA 二人三脚で進めるSLO運用/sre-qa-slo
sugitak
0
1k
企業でAWS Organizationsを動かすための組織設計の考え方
nrinetcom
PRO
1
110
Data + AI Summit 2026 イベントレポート: 「AIがビジネスで意思決定するデータ基盤」へ
nek0128
0
290
仕様駆動開発、導入半年。「本当に速くなってるの?」にデータで答える / AICon2026_hirakawa
rakus_dev
0
150
壊して学ぶAWS CDK: そのcdk deployで消えるもの、残るもの
k_adachi_01
1
430
LLMやAIエージェントをソフトウェアに組み込むプラクティス
shibuiwilliam
2
430
AIレビューはどこまで任せられるのか?自動化と人が背負うレビューの境界
sansantech
PRO
3
1.1k
知らん間に、回ってる
ming_ayami
0
740
kaonavi Tech Night#1
kaonavi
0
120
シンガポールで登壇してきます
yama3133
0
250
AI時代のYAGNI:「爆速で無駄になった機能」からの学び / 20260720 Naoki Takahashi
shift_evolve
PRO
3
390
DatabricksにおけるMCPソリューション
taka_aki
1
280
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
310
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
340
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
My Coaching Mixtape
mlcsv
0
170
Transcript
Visualization of mechanical CAD drawings using WebAssembly and WebGL Rust
Tokyo 2019 @TaigaMerlin
Introduction • Aki, CTO @ CADDi Inc (キャディ株式会社) • Former
embedded engineer • Following Rust since 0.9 • Eagerly awaiting 1.39 (ha)
Agenda 1. State of CAD software 2. WebAssembly 3. WebGL
4. Results 5. Learnings
State of CAD software
[C]omputer [A]ided [D]esign grabcad.com/library/engine-v-twin
[C]omputer [A]ided [D]esign www.eventshigh.com
CAD in manufacturing 3D geometric kernels • Open CASCADE (C++,
OSS) • Parasolid (C, proprietary) • ACIS (C++, proprietary) 2D drawing used in procurement • rust dxf (Rust, OSS) • libdxfrw (C++, OSS)
Objective: 2D drawings in the browser
None
Binary code format that runs in a host environment
Not just for the web! (See WASI)
Host environment What is WebAssembly? C++, Rust, etc .wasm .js
.html .css
What is WebAssembly? caniuse.com
What is WebAssembly? caniuse.com
Who’s using WebAssembly? ...and many more!
Show me the Rust code!
WebAssembly sample ----- RUST ----- #[no_mangle] pub extern fn add(a:
i32, b: i32) -> i32 { a+b }
WebAssembly sample ----- RUST ----- #[no_mangle] pub extern fn add(a:
i32, b: i32) -> i32 { a+b } ----- WASM/WAT ----- (func $add (type 1) (param i32 i32) (result i32) local.get 0 local.get 1 i32.add)
WebAssembly is typed ----- RUST ----- #[no_mangle] pub extern fn
add(a: i32, b: i32) -> i32 { a+b } ----- WASM/WAT ----- (func $add (type 1) (param i32 i32) (result i32) local.get 0 local.get 1 i32.add)
WebAssembly resembles a stack machine ----- RUST ----- #[no_mangle] pub
extern fn add(a: i32, b: i32) -> i32 { a+b } ----- WASM/WAT ----- (func $add (type 1) (param i32 i32) (result i32) local.get 0 ← push arg 0 onto the stack local.get 1 i32.add)
WebAssembly resembles a stack machine ----- RUST ----- #[no_mangle] pub
extern fn add(a: i32, b: i32) -> i32 { a+b } ----- WASM/WAT ----- (func $add (type 1) (param i32 i32) (result i32) local.get 0 ← push arg 0 onto the stack local.get 1 ← push arg 1 onto the stack i32.add)
WebAssembly resembles a stack machine ----- RUST ----- #[no_mangle] pub
extern fn add(a: i32, b: i32) -> i32 { a+b } ----- WASM/WAT ----- (func $add (type 1) (param i32 i32) (result i32) local.get 0 ← push arg 0 onto the stack local.get 1 ← push arg 1 onto the stack i32.add) ← execute math operation
WebAssembly resembles a stack machine ----- RUST ----- #[no_mangle] pub
extern fn add(a: i32, b: i32) -> i32 { a+b } ----- WASM/WAT ----- (func $add (type 1) (param i32 i32) (result i32) local.get 0 ← push arg 0 onto the stack local.get 1 ← push arg 1 onto the stack i32.add) ← execute math operation
WebAssembly: numeric instructions
WebAssembly: trigonometry?
WebAssembly: trigonometry?
I want my transcendental functions!
I want my transcendental functions!
WebAssembly interfacing with host environment
Rust (.wasm) ⇔ JavaScript (.js) ----- Rust ----- pub fn
rust_function () { unsafe { js_function (); } } ----- JavaScript ----- wasm.instance.exports.rust_function (); Calling Rust from JavaScript Calling JavaScript from Rust
Call a Rust function from JavaScript ----- Rust ----- #[no_mangle]
pub extern fn add(a: i32, b: i32) -> i32 { a + b } ----- SHELL ----- $ rustc -O --target=wasm32-unknown-unknown example.rs -o example.wasm ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), {}) .then(wasm => { var add_func = wasm.instance.exports.add; }); </script>
Call a Rust function from JavaScript ----- Rust ----- #[no_mangle]
pub extern fn add(a: i32, b: i32) -> i32 { a + b } ----- SHELL ----- $ rustc -O --target=wasm32-unknown-unknown example.rs -o example.wasm ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), {}) .then(wasm => { var add_func = wasm.instance.exports.add; }); </script> - WebAssembly has no main() - It behaves like a JS module/library
Call a Rust function from JavaScript ----- Rust ----- #[no_mangle]
pub extern fn add(a: i32, b: i32) -> i32 { a + b } ----- SHELL ----- $ rustc -O --target=wasm32-unknown-unknown example.rs -o example.wasm ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), {}) .then(wasm => { var add_func = wasm.instance.exports.add; var result = add_func(10, 20); console.log(result); }); </script>
Call a Rust function from JavaScript ----- Rust ----- #[no_mangle]
pub extern fn add(a: i32, b: i32) -> i32 { a + b } ----- SHELL ----- $ rustc -O --target=wasm32-unknown-unknown example.rs -o example.wasm ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), {}) .then(wasm => { var add_func = wasm.instance.exports.add; var result = add_func(10, 20); console.log(result); }); </script>
Call a Rust function from JavaScript • Can be used
to implement compute heavy code in Rust • Access those functions from JavaScript • eg: Image resizing algorithm for an image editing online tool
Where are my transcendental functions?
Call a JavaScript function from Rust ----- Rust ----- #[link(wasm_import_module
= "imports")] extern { fn cos(theta: f64) -> f64; } #[no_mangle] pub extern fn do_trig() { unsafe { cos(0.0); } } ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), { imports: { cos: (x) => Math.cos(x) } }) .then(wasm => { wasm.instance.exports.do_trig(); }); </script>
Call a JavaScript function from Rust ----- Rust ----- #[link(wasm_import_module
= "imports")] extern { fn cos(theta: f64) -> f64; } #[no_mangle] pub extern fn do_trig() { unsafe { cos(0.0); } } ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), { imports: { cos: (x) => Math.cos(x) } }) .then(wasm => { wasm.instance.exports.do_trig(); }); </script>
Call a JavaScript function from Rust ----- Rust ----- #[link(wasm_import_module
= "imports")] extern { fn cos(theta: f64) -> f64; } #[no_mangle] pub extern fn do_trig() { unsafe { cos(0.0); } } ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), { imports: { cos: (x) => Math.cos(x) } }) .then(wasm => { wasm.instance.exports.do_trig(); }); </script>
Call a JavaScript function from Rust ----- Rust ----- #[link(wasm_import_module
= "imports")] extern { fn cos(theta: f64) -> f64; } #[no_mangle] pub extern fn do_trig() { unsafe { cos(0.0); } } ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), { imports: { cos: (x) => Math.cos(x) } }) .then(wasm => { wasm.instance.exports.do_trig(); }); </script> - We probably want a debug print… - But WebAssembly has no I/O!
Let’s print the result! JavaScript Math.cos() Rust do_trig() cos()
Let’s print the result! JavaScript Math.cos() console.log() Rust do_trig() cos()
Let’s print the result! JavaScript Math.cos() console.log() Rust do_trig() cos()
console_log()
Call a JavaScript function from Rust ----- RUST ----- #[link(wasm_import_module
= "imports")] extern { fn console_log (x: f64); fn cos(theta: f64) -> f64; } #[no_mangle] pub extern fn do_trig() { unsafe { console_log (cos(0.0)); console_log (cos(3.14/4.0)); } } ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), { imports: { console_log : (x) => console.log(x), cos: (x) => Math.cos(x) } }) .then(wasm => { wasm.instance.exports.do_trig(); }); </script>
Call a JavaScript function from Rust ----- RUST ----- #[link(wasm_import_module
= "imports")] extern { fn console_log (x: f64); fn cos(theta: f64) -> f64; } #[no_mangle] pub extern fn do_trig() { unsafe { console_log (cos(0.0)); console_log (cos(3.14/4.0)); } } ----- HTML ----- <script> WebAssembly .instantiateStreaming ( fetch('example.wasm' ), { imports: { console_log : (x) => console.log(x), cos: (x) => Math.cos(x) } }) .then(wasm => { wasm.instance.exports.do_trig(); }); </script>
Yay transcendental functions!
Call a JavaScript function from Rust ----- RUST ----- #[link(wasm_import_module
= "imports")] extern { fn console_log (x: f64); } #[no_mangle] pub extern fn do_trig() { ... } Imported function Exported function
example.wasm WebAssembly Format (abridged) Import section Export section console_log() #0
do_trig() #3
example.wasm WebAssembly Format (abridged) Import section Export section console_log() Code
section local.get 0 local.get 1 i32.add #2 #0 do_trig() #3 Data section 0x67 0x65 0x74 0x20 0x74 0x68 0x69 0x73 0x3f 0x20 0x44 0x4d 0x20 0x6d 0x65 #0
example.wasm WebAssembly Format (abridged) Import section Export section console_log() Code
section local.get 0 local.get 1 i32.add #2 #0 do_trig() #3 Data section Memory section: declares linear memory regions 0x67 0x65 0x74 0x20 0x74 0x68 0x69 0x73 0x3f 0x20 0x44 0x4d 0x20 0x6d 0x65 #0
.wasm file WebAssembly DATA CODE LINEAR MEMORY PROCESSOR program memory
program instructions
WebAssembly has a Harvard-like architecture DATA PROCESSOR CODE I/O
None
3D Applications Raytracing experiments.withgoogle.com newnaw.com What can WebGL do?
What is WebGL? • JavaScript API for 2D and 3D
rendering in the browser caniuse.com
What is WebGL2? • WebGL ⇒ WebGL2 ⇒ WebGPU(?) caniuse.com
What is WebGL2? • WebGL ⇒ WebGL2 ⇒ WebGPU(?) caniuse.com
The difficulty with graphics APIs
Software architecture Native Application Native CAD library (x86) Graphics stack
(OpenGL)
Software architecture Native Application Native CAD library (x86) Graphics stack
(OpenGL) Web Application Native CAD library (wasm) Graphics stack (WebGL) vs
Software architecture Native Application Native CAD library (x86) Graphics stack
(OpenGL) Web Application Native CAD library (wasm) Graphics stack (WebGL) vs - kiss3d (graphics engine supporting WebGL) - rust-dxf (native DXF file parser)
Results
Results
Current challenges • Text rendering for CJK languages (Font support,
garbled text, etc) • Running native code expecting native syscalls and interfaces (Emscripten) • Rust graphics ecosystem is still young
Access all JavaScript APIs from WebAssembly
• wasm-bindgen • web-sys: DOM, WebGL, WebAudio, etc • js-sys:
ECMAScript Rust and JavaScript coexist peacefully
The future is bright!
Thank you! @TaigaMerlin