126 lines
3.2 KiB
JavaScript
126 lines
3.2 KiB
JavaScript
|
|
import keplerEngine from './engine/kepler.js';
|
||
|
|
import entity from './engine/entity.js';
|
||
|
|
import material from './engine/material.js';
|
||
|
|
import sampler2D from './engine/sampler2D.js';
|
||
|
|
import mesh from './engine/mesh.js';
|
||
|
|
import viewport from './engine/viewport.js';
|
||
|
|
import {matrix4} from './engine/math.js';
|
||
|
|
import template from './engine/renderPasses/template.js';
|
||
|
|
import sceneNode from './engine/sceneNode.js';
|
||
|
|
|
||
|
|
kepler = new keplerEngine();
|
||
|
|
|
||
|
|
// Viewport
|
||
|
|
var ViewPort = new viewport("keplerEngine");
|
||
|
|
|
||
|
|
// Load model
|
||
|
|
kepler.assimpLoader.load( "demo.json", ViewPort.scene );
|
||
|
|
|
||
|
|
// Add viewport
|
||
|
|
kepler.addViewport( ViewPort );
|
||
|
|
|
||
|
|
// Material
|
||
|
|
var groundMaterial = new material();
|
||
|
|
|
||
|
|
// Samplers
|
||
|
|
var normalTexture = kepler.resources.getTexture("floorTiles_normal");
|
||
|
|
var normalSampler = new sampler2D();
|
||
|
|
normalSampler.addTexture(normalTexture);
|
||
|
|
|
||
|
|
var diffuseTexture = kepler.resources.getTexture("floorTiles_diff");
|
||
|
|
var diffuseSampler = new sampler2D();
|
||
|
|
diffuseSampler.addTexture(diffuseTexture);
|
||
|
|
|
||
|
|
groundMaterial.addTexture(diffuseSampler);
|
||
|
|
groundMaterial.addNormal(normalSampler);
|
||
|
|
//groundMaterial.addRoughness(normalSampler);
|
||
|
|
|
||
|
|
// Properties
|
||
|
|
groundMaterial.diffuseColor = [179/256,199/256,217/256];
|
||
|
|
groundMaterial.alpha = 1;
|
||
|
|
groundMaterial.reflection = 0.2;
|
||
|
|
groundMaterial.roughness = 0.3;
|
||
|
|
groundMaterial.metalic = 0.1;
|
||
|
|
groundMaterial.uvMultiplier = 6;
|
||
|
|
groundMaterial.create();
|
||
|
|
|
||
|
|
// Cube mesh
|
||
|
|
var cubeMesh = ViewPort.primitives.createCube(10);
|
||
|
|
cubeMesh.addMaterial(groundMaterial);
|
||
|
|
|
||
|
|
// Cube Entity
|
||
|
|
var cubeEntity = new entity( );
|
||
|
|
cubeEntity.addMesh( cubeMesh );
|
||
|
|
cubeEntity.name = "sky sphere";
|
||
|
|
cubeEntity.transform.position = [0, -10, 0];
|
||
|
|
cubeEntity.transform.update();
|
||
|
|
|
||
|
|
ViewPort.scene.addEntity( cubeEntity );
|
||
|
|
|
||
|
|
// Start application
|
||
|
|
kepler.application();
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// Template.js
|
||
|
|
|
||
|
|
import framebuffer from '../framebuffer.js';
|
||
|
|
import sampler2D from '../sampler2D.js';
|
||
|
|
import {math, vector3, matrix4} from '../math.js';
|
||
|
|
import samplerCube from '../samplerCube.js';
|
||
|
|
import shader from '../shader.js';
|
||
|
|
|
||
|
|
class template {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* set viewport
|
||
|
|
* @param {(viewport)} viewport
|
||
|
|
**/
|
||
|
|
setViewport( viewport ){
|
||
|
|
|
||
|
|
this.viewport = viewport;
|
||
|
|
this.gl = viewport.gl;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
prepare() {
|
||
|
|
|
||
|
|
this.width = this.viewport.width;
|
||
|
|
this.height = this.viewport.height;
|
||
|
|
|
||
|
|
this.targetSampler = new sampler2D( );
|
||
|
|
this.targetSampler.type = this.gl.FLOAT;
|
||
|
|
|
||
|
|
this.framebuffer = new framebuffer( );
|
||
|
|
this.framebuffer.setViewport( this.viewport );
|
||
|
|
|
||
|
|
this.framebuffer.width = this.width;
|
||
|
|
this.framebuffer.height = this.height;
|
||
|
|
|
||
|
|
this.framebuffer.addSampler( this.targetSampler );
|
||
|
|
this.framebuffer.create();
|
||
|
|
|
||
|
|
|
||
|
|
this.shader = new shader();
|
||
|
|
this.shader.createFromFile("shaders/template.shader");
|
||
|
|
|
||
|
|
this.shader.setUniform("viewProjection", this.viewport.quad.viewProjection );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
render() {
|
||
|
|
|
||
|
|
//this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer.glFramebuffer);
|
||
|
|
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);
|
||
|
|
|
||
|
|
this.gl.clearColor( 0, 0, 0, 1 );
|
||
|
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
|
||
|
|
|
||
|
|
this.viewport.quad.draw( this.shader );
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export {template as default};
|