1 | <h1 align="center">
|
2 | <img src="https://user-images.githubusercontent.com/7625588/53308816-3041ec80-38df-11e9-9c3a-fb515eb4d404.png">
|
3 | </h1>
|
4 |
|
5 | [![Build Status](https://travis-ci.org/but0n/Ashes.svg?branch=master)](https://travis-ci.org/but0n/Ashes)
|
6 | [![](https://badgen.net/bundlephobia/minzip/ashes3d)](https://bundlephobia.com/result?p=ashes3d)
|
7 | [![](https://data.jsdelivr.com/v1/package/npm/ashes3d/badge)](https://www.jsdelivr.com/package/npm/ashes3d)
|
8 |
|
9 | ![](https://user-images.githubusercontent.com/7625588/52896085-bbdfbd00-31fd-11e9-944d-cfed12c18cbd.png)
|
10 |
|
11 | ### [glTF-test](https://cx20.github.io/gltf-test/?engines=Ashes) by [cx20](https://github.com/cx20)
|
12 |
|
13 | ## Getting Started
|
14 |
|
15 | - via CDN
|
16 | ```html
|
17 | <script src="https://cdn.jsdelivr.net/npm/ashes3d/build/ashes.main.js"></script>
|
18 | ```
|
19 | - via npm
|
20 | ```
|
21 | npm -i ashes3d
|
22 | ```
|
23 |
|
24 | ## Usage
|
25 |
|
26 | [Try it](https://codepen.io/but0n/pen/daERdd)
|
27 |
|
28 | ```js
|
29 |
|
30 | let { Asset, EntityMgr, Camera, vec3, quat, Screen, OrbitControl, MeshRenderer, Filter, Shader, Material, QuadMesh } = Ashes;
|
31 |
|
32 | let CDN = 'https://but0n.github.io/Ashes/'
|
33 | Material.SHADER_PATH = CDN + Material.SHADER_PATH;
|
34 |
|
35 |
|
36 | // DamagedHelmet
|
37 | let gltf = CDN + 'gltfsamples/DamagedHelmet.glb';
|
38 |
|
39 |
|
40 | async function main() {
|
41 |
|
42 | let screen = new Screen('#screen');
|
43 |
|
44 | screen.bgColor = [0.2,0.2,0.2,1];
|
45 |
|
46 |
|
47 | let skybox = await Asset.loadCubemap(CDN + 'res/envmap/GoldenGateBridge2/');
|
48 |
|
49 | let scene = EntityMgr.create('root - (Click each bar which has yellow border to toggle visible)');
|
50 |
|
51 | // Camera
|
52 | let mainCamera = EntityMgr.create('camera');
|
53 | let cam = EntityMgr.addComponent(mainCamera, new Camera(screen.width / screen.height));
|
54 |
|
55 | // Set default position
|
56 | let cameraTrans = mainCamera.components.Transform;
|
57 | vec3.set(cameraTrans.translate, 0, 10, 10);
|
58 |
|
59 | // Add it to scene
|
60 | scene.appendChild(mainCamera);
|
61 |
|
62 | // Attach controler
|
63 | EntityMgr.addComponent(mainCamera, new OrbitControl(screen, mainCamera));
|
64 |
|
65 | document.querySelector('body').appendChild(scene);
|
66 |
|
67 | // Load a gltf model
|
68 | let gltfroot = await Asset.loadGLTF(gltf, screen, skybox);
|
69 | scene.appendChild(gltfroot);
|
70 |
|
71 | }
|
72 |
|
73 | main();
|
74 |
|
75 | ```
|
76 |
|
77 | ### Create a quad with texture
|
78 |
|
79 | ```js
|
80 | // Create an entity
|
81 | let quad = scene.appendChild(EntityMgr.create('quad'));
|
82 |
|
83 | // Load a material
|
84 | let quadMat = await Asset.LoadMaterial('stylize'); // PBR material
|
85 |
|
86 | // Load a texture
|
87 | let floor = await Asset.loadTexture(CDN + 'res/textures/floor.png', { minFilter: screen.gl.NEAREST_MIPMAP_NEAREST });
|
88 | floor.flipY = true;
|
89 |
|
90 | // Attach texture to material we created
|
91 | Material.setTexture(quadMat, 'baseColorTexture', floor);
|
92 | quadMat.shader.macros['HAS_BASECOLOR_MAP'] = '';
|
93 |
|
94 | // Create a renderer component
|
95 | let quadMR = new MeshRenderer(screen, new QuadMesh(), quadMat);
|
96 |
|
97 | // Attach renderer to entity
|
98 | EntityMgr.addComponent(quad, quadMR);
|
99 |
|
100 | // Set local translate [x, y, z]
|
101 | quad.components.Transform.translate[1] = -1;
|
102 |
|
103 | // Set euler angle x, y, z
|
104 | quat.fromEuler(quad.components.Transform.quaternion, -90, 0, 0);
|
105 |
|
106 | // The original size of quad is 2x2
|
107 | vec3.scale(quad.components.Transform.scale, quad.components.Transform.scale, 9);
|
108 |
|
109 | ```
|
110 |
|
111 | ## Deployment
|
112 |
|
113 | ```sh
|
114 | git clone https://github.com/but0n/Ashes.git
|
115 | cd Ashes
|
116 |
|
117 | # if you don't have yarn installed
|
118 | npm install -g yarn
|
119 |
|
120 | yarn
|
121 |
|
122 | yarn dev
|
123 | ```
|
124 |
|