zdog README

The project's README from github.com/metafizzy/zdog. As one markdown file: README.md.

Zdog

Round, flat, designer-friendly pseudo-3D engine

View complete documentation and live demos at zzz.dog.

Install

Download

CDN

Link directly to Zdog JS on unpkg.

<script src="https://unpkg.com/zdog@1/dist/zdog.dist.min.js"></script>

Package managers

npm: npm install zdog

Bower: bower install zdog

Hello world demo

Create 3D models with Zdog by adding shapes. See Getting started for a walk-through of this demo.

let isSpinning = true;

let illo = new Zdog.Illustration({
  element: '.zdog-canvas',
  zoom: 4,
  dragRotate: true,
  // stop spinning when drag starts
  onDragStart: function() {
    isSpinning = false;
  },
});

// circle
new Zdog.Ellipse({
  addTo: illo,
  diameter: 20,
  translate: { z: 10 },
  stroke: 5,
  color: '#636',
});

// square
new Zdog.Rect({
  addTo: illo,
  width: 20,
  height: 20,
  translate: { z: -10 },
  stroke: 3,
  color: '#E62',
  fill: true,
});

function animate() {
  illo.rotate.y += isSpinning ? 0.03 : 0;
  illo.updateRenderGraph();
  requestAnimationFrame( animate );
}
animate();

About Zdog

Hi, Dave here. I wanted to make a video game. I needed a 3D engine, but most engines were too powerful and complex for me. I made Zdog so I could design and display simple 3D models without a lot of overhead.

Zdog is directly inspired by Dogz, a virtual pet game by P.F. Magic released in 1995. It used flat 2D circle sprites to render the Dogz’ models, but in a 3D scene. See Dogz playthrough video here. Dogz were fully animated in real time, running, flopping, scratching (on Windows 3.1!). It was remarkable.

Zdog uses the same principle. It renders all shapes using the 2D drawing APIs in either <canvas> or <svg>. Spheres are actually dots. Toruses are actually circles. Capsules are actually thick lines. It’s a simple, but effective trick. The underlying 3D math comes from Rotating 3D Shapes by Peter Collingridge.

Zdog is pronounced "Zee-dog" in American parlance or "Zed-dog" in British.

Beta!

Zdog v1 is a beta-release, of sorts. This is my first time creating a 3D engine, so I probably got some stuff wrong. Expect lots of changes for v2. Provide input and select new features on the Zdog issue tracker on GitHub.

More Zdog resources

Other people's stuff:

My stuff:


Licensed MIT. Made by Metafizzy 🌈🐻

zdog (metafizzy/zdog)

Searching Database…

10.7K ·GitHub
这是什么东西?Zdog 是一个圆润、扁平、对设计师友好的网页伪 3D 引擎:你用 JavaScript 添加各种形状来搭建 3D 模型,它再通过 2D 绘图 API 把模型渲染到 canvas 或 SVG 上。
它是真正的 3D 引擎吗?还是说「伪 3D」是什么意思?它其实是个小技巧:Zdog 把扁平的 2D 形状摆放在 3D 空间里来绘制——球体其实就是一个个圆点,圆环就是圆形,胶囊体就是粗线条。旋转的计算是真正的 3D 数学,只有渲染出来的画面是扁平的,原理和启发它的 1995 年游戏 Dogz 一样。
我怎么把它加到网页里?可以用 npm install zdog 安装(Bower 也可以),从 unpkg CDN 引入 zdog.dist.min.js,或者直接下载文件。文档和在线演示都在 zzz.dog 上。
它需要其他库或者构建步骤吗?不需要。它就是一个纯 JavaScript 文件,没有任何运行时依赖,加一个 script 标签或者跑一次 npm install 就够了。
它稳定吗?还是还在改动?把它当成 beta 版来看:作者称 v1「算是某种意义上的 beta 版」,并表示 v2 会有大量改动,所以 API 可能会变。
作者为什么不直接用现成的 3D 引擎,而要自己写一个?Metafizzy 的 Dave 本来想做一款视频游戏,但发现真正的引擎太强大也太复杂,于是他做了 Zdog,用很少的开销就能设计和展示简单的 3D 模型。它的灵感直接来自 1995 年的虚拟宠物游戏 Dogz。
怎么用它搭建模型?你通过在代码里往场景中添加形状来创建模型——球体、圆环、胶囊体之类。zzz.dog 上的 Getting started 指南会带你完整走一遍 hello-world 演示。
它周边有生态吗?有:Zfont 是文字插件,vue-zdog 是 Vue 的封装,zDogPy 是面向 DrawBot 的 Python 移植版,另外还有 Made with Zdog 的 CodePen 和 Twitter 合集可以找灵感。
Zdog 怎么读?美式读法是「Zee-dog」,英式读法是「Zed-dog」。
Creator
metafizzy
Size
0.6 MB
Stars
10.7K
Age
7y
Commits · 90 Days