Skip to content
WebGL 2.0 playground
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gltfsamples @ aaaeb69
res
src
.gitignore
.gitmodules
.npmignore
.travis.yml
LICENSE
README.md
demo.html add version Apr 4, 2019
index.html
package.json
rollup.config.js
tsconfig.json
yarn.lock

README.md

Build Status

Examples

Getting Started

  • via CDN
<script src="https://cdn.jsdelivr.net/npm/ashes3d/build/ashes.main.js"></script>
  • via npm
npm i ashes3d

Usage

Try it

let { Asset, EntityMgr, Camera, vec3, quat, Screen, OrbitControl, MeshRenderer, Filter, Shader, Material, QuadMesh } = Ashes;

let CDN = 'https://but0n.github.io/Ashes/'
Material.SHADER_PATH = CDN + Material.SHADER_PATH;


// DamagedHelmet
let gltf = CDN + 'gltfsamples/DamagedHelmet.glb';


async function main() {

    let screen = new Screen('#screen');

    screen.bgColor = [0.2,0.2,0.2,1];


    let skybox = await Asset.loadCubemap(CDN + 'res/envmap/GoldenGateBridge2/');

    let scene = EntityMgr.create('root - (Click each bar which has yellow border to toggle visible)');

    // Camera
    let mainCamera = EntityMgr.create('camera');
    let cam = mainCamera.addComponent(new Camera(screen.width / screen.height));

    // Set default position
    let cameraTrans = mainCamera.components.Transform;
    vec3.set(cameraTrans.translate, 0, 10, 10);

    // Add it to scene
    scene.appendChild(mainCamera);

    // Attach controler
    mainCamera.addComponent(new OrbitControl(screen, mainCamera));

    document.querySelector('body').appendChild(scene);

    // Load a gltf model
    let gltfroot = await Asset.loadGLTF(gltf, screen, skybox);
    scene.appendChild(gltfroot);

}

main();

Create a quad with texture

    // Create an entity
    let quad = scene.appendChild(EntityMgr.create('quad'));

    // Load a material
    let quadMat = await Asset.LoadMaterial('stylize'); // PBR material

    // Load a texture
    let floor = await Asset.loadTexture(CDN + 'res/textures/floor.png', { minFilter: screen.gl.NEAREST_MIPMAP_NEAREST });
    floor.flipY = true;

    // Attach texture to material we created
    Material.setTexture(quadMat, 'baseColorTexture', floor);
    quadMat.shader.macros['HAS_BASECOLOR_MAP'] = '';

    // Create a renderer component
    let quadMR = new MeshRenderer(screen, new QuadMesh(), quadMat);

    // Attach renderer to entity
    quad.addComponent(quadMR);

    // Set local translate [x, y, z]
    quad.components.Transform.translate[1] = -1;

    // Set euler angle x, y, z
    quat.fromEuler(quad.components.Transform.quaternion, -90, 0, 0);

    // The original size of quad is 2x2
    vec3.scale(quad.components.Transform.scale, quad.components.Transform.scale, 9);

Deployment

git clone https://github.com/but0n/Ashes.git
cd Ashes

# if you don't have yarn installed
npm install -g yarn

yarn

yarn dev
You can’t perform that action at this time.