惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
G
Google Developers Blog
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
小众软件
小众软件
月光博客
月光博客
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
P
Proofpoint News Feed
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
The Cloudflare Blog
博客园_首页
美团技术团队
大猫的无限游戏
大猫的无限游戏
B
Blog
IT之家
IT之家
Jina AI
Jina AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟
Spline library for Snap!
种瓜 · 2024-06-14 · via 夜行人

文章目录

中文版本

Preface

My interest in 3D environments came from this paper by Croquet team.

I learned this perspective on interactive graphical computing from Alan Kay: the power of desktop metaphor/GUI is psychological, it create a “illusion” for users, as if things are right there on the screen, so users can transfer their real-world experience, just like dealing with physical objects, to interacting with virtual objects on the screen.

From this perspective, we naturally crave a 3D environment because it can further enhance this “user illusion” that things exist in a virtual 3D space rather than on a 2D “desktop.” As a result, users can more easily transfer their experiences from the real world (the real world is a kind of 3D space).

These ideas focus on making computing adapt to humans, rather than making humans adapt to computing.

Introducing 3D world into Snap!

The stage provided by Snap! is usually used to make 2D projects. I was eager to introduce 3D world into Snap!.

There are many ways to achieve goals:

The iframe library provides this possibility.

My idea is:

  • Introducing web-based 3D world into Snap! using the iframe library.
  • With postMessage API, Snap! can communicate with the 3D world inside an iframe

I need to choose a 3D engine to demonstrate how to implement the above ideas. After some comparison, I chose Spline, which is simple and easy. Spline has many similarities with Scratch, and it greatly reduces the difficulty of 3D creation.

It is possible to create a 3D editor(based on threejs or babylonjs) for Snap!, just like Snap!’s Bitmap Paint Editor/Vector Paint Editor, deeply integrated into Snap!. The downside of doing this is the development workload is huge, and it is doubtful whether it is as easy to use. I ultimately abandoned this idea and instead started thinking about:

Which 3D editor is easy to use and exposes an API for interaction? If such a editor exists, we can consider it as an “external editor” for Snap!

Spline is responsible for creating 3D projects and exposing API and Snap! is responsible for programming and control. Operating a Spline project in Snap! is similar to operating a MicroBlocks project in Snap!. Spline and MicroBlocks is responsible for “internal Programming”, providing services externally, while Snap! acts as a client using these services.

demo 1

Project link (Click to Run)

You can export the project and load it in Snap!Cloud, remember to enable JavaScript extensions

Spline project used for demonstration, remixed from Little World Kawaii Pig

The world url filled in Snap! is https://prod.spline.design/s7FG1KdbdsyW8yOY/scene.splinecode (FAQ explains how to get the world url of a project)

demo2

Project link (Click to Run)

Spline project used for demonstration, remixed from Mini House - Conditional Logic

The world url filled in Snap! is https://prod.spline.design/nO5gRl8xdZ5gp4UJ/scene.splinecode

demo3: get and set variable

Project link (Click to Run)

Spline project used for demonstration, remixed from 3D Text - Blue.

The world url filled in Snap! is https://prod.spline.design/CJdfFOXzOrARU5Nz/scene.splinecode

About the usage of variables in Spline, refer to this tutorial

FAQ

How to get the world url

How to self-host project files?

Taking demo 2 (https://prod.spline.design/dP5NwOaNd2IR5Npm/scene.splinecode) as an example, you can download it, store it on your own server (I put it at: https://wwj718.github.io/post/img/scene.splinecode ), and then load it.

Project link (Click to Run)

How does the open world url block work?

open world url block requires a url parameter, like https://prod.spline.design/nO5gRl8xdZ5gp4UJ/scene.splinecode, you can get the url from the Export button of a Splne project.

Within open world url block , it will pass the url to this iframe page: https://wwj718.github.io/Snap-Spline-Demo?project=https://prod.spline.design/nO5gRl8xdZ5gp4UJ/scene.splinecode

The source code of the iframe page is here: Snap-Spline-Demo.

What APIs does Spline expose?

Here is the API description.

These APIs determine how external systems (such as Snap!) can interact with Spline projects.

What is the use of dynatalk-over-postmessage blocks

Everything is an object
Objects communicate via messages
The object interprets the message it understands
– Alan Kay

The browser provides the postMessage API for communicating with iframe pages, which is an asynchronous communication (pub/sub) method. Sometimes we want synchronous communication (such as the ask _ for _ blocks of the Spline library), similar to RPC or function call. Dynatalk can achieve this.

Creating dynatalk-over-postmessage is esay. It only needs to switch the message channel from MQTT to postMessage. Specifically, the mechanism for receiving and sending messages needs to be adjusted.

References