Skip to content

Commit

Permalink
Refactor sample folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Feb 28, 2019
1 parent 55228ba commit d6c3ad5
Show file tree
Hide file tree
Showing 34 changed files with 168 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; URL=test">
<meta http-equiv="refresh" content="0; URL=samples">
</head>
<body>
</body>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"serv": "node server.js",
"test": "yarn test-unit ; yarn test-e2e",
"test-unit": "jest --config jest.config.js ./src",
"test-e2e": "JEST_PUPPETEER_CONFIG=jest-puppeteer-config.js jest ./test/e2e --runInBand --config jest.config.e2e.js",
"test-e2e-update": "JEST_PUPPETEER_CONFIG=jest-puppeteer-config.js jest ./test/e2e --runInBand --config jest.config.e2e.js --updateSnapshot",
"test-e2e": "JEST_PUPPETEER_CONFIG=jest-puppeteer-config.js jest ./samples/test_e2e --runInBand --config jest.config.e2e.js",
"test-e2e-update": "JEST_PUPPETEER_CONFIG=jest-puppeteer-config.js jest ./samples/test_e2e --runInBand --config jest.config.e2e.js --updateSnapshot",
"test-coverage": "jest --coverage",
"doc": "typedoc --includeDeclarations --exclude '**/*.test.ts' --out ./docs/ ./src/"
},
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion test/example-list.json → samples/example-list.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"e2e": [
"test_e2e": [
"DataTextureInstancedDrawingWebGL1",
"DataTextureInstancedDrawingWebGL2",
"Gltf2Importer",
"UBOInstancedDrawing"
],
"simple": [
"Effekseer",
"SparkGear"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test('regression test DataTextureInstancedDrawingWebGL1', async () => {
jest.setTimeout(60000);
const page = await browser.newPage();
await page.goto('http://localhost:8082/test/e2e/DataTextureInstancedDrawingWebGL1');
await page.goto('http://localhost:8082/samples/test_e2e/DataTextureInstancedDrawingWebGL1');
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 60000});
const canvasElement = await page.$('#world');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test('regression test DataTextureInstancedDrawingWebGL2', async () => {
jest.setTimeout(60000);
const page = await browser.newPage();
await page.goto('http://localhost:8082/test/e2e/DataTextureInstancedDrawingWebGL2');
await page.goto('http://localhost:8082/samples/test_e2e/DataTextureInstancedDrawingWebGL2');
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 60000});
const canvasElement = await page.$('#world');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions samples/test_e2e/Gltf2Importer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<html>
<head>
<title>Gltf2Importer</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<style>
main {
display: flex;
}
section {
background-color: darkgray;
padding: 10px;
margin: 20px;
}
</style>
</head>
<body>
<header>
<h1 class="header-title">Rhodonite E2E Test - Gltf2Importer</h1>
</header>
<main>
<section class="test">
<h2>Rendering Test Image</h2>
<canvas id="world" width="600" height="600"></canvas>
<div>
<button onclick="window.isAnimating = true;">Animate</button>
</div>
</section>
<section class="correct">
<h2>Correct PNG Image</h2>
<img src="__image_snapshots__/test-js-regression-test-gltf-2-importer-1-snap.png" />
</section>
</main>
<script src="../../assets/navigate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js"></script>
<script src="../../../dist/rhodonite.js"></script>
<script src="main.js"></script>
</body>

</html>
103 changes: 103 additions & 0 deletions samples/test_e2e/Gltf2Importer/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

let p = null;

const load = async function(time){
await Rn.ModuleManager.getInstance().loadModule('webgl');
await Rn.ModuleManager.getInstance().loadModule('pbr');
const importer = Rn.Gltf2Importer.getInstance();
const system = Rn.System.getInstance();
const gl = system.setProcessApproachAndCanvas(Rn.ProcessApproach.UniformWebGL1, document.getElementById('world'));

const entityRepository = Rn.EntityRepository.getInstance();

// Camera
const cameraEntity = entityRepository.createEntity([Rn.TransformComponent, Rn.SceneGraphComponent, Rn.CameraComponent, Rn.CameraControllerComponent])
const cameraComponent = cameraEntity.getComponent(Rn.CameraComponent);
//cameraComponent.type = Rn.CameraTyp]e.Orthographic;
cameraComponent.parameters = new Rn.Vector4(0.1, 1000, 90, 1);
cameraEntity.getTransform().translate = new Rn.Vector3(0.0, 0, 0.5);


// Lights
const lightEntity = entityRepository.createEntity([Rn.TransformComponent, Rn.SceneGraphComponent, Rn.LightComponent])
lightEntity.getTransform().translate = new Rn.Vector3(1.0, 100000.0, 1.0);
lightEntity.getComponent(Rn.LightComponent).intensity = new Rn.Vector3(1, 1, 1);
//lightEntity2.getTransform().rotate = new Rn.Vector3(Math.PI/2, 0, 0);
//lightEntity2.getComponent(Rn.LightComponent).type = Rn.LightType.Directional;


const response = await importer.import('../../../assets/gltf/2.0/BoxAnimated/glTF/BoxAnimated.gltf');
const modelConverter = Rn.ModelConverter.getInstance();
const rootGroup = modelConverter.convertToRhodoniteObject(response);
//rootGroup.getTransform().translate = new Rn.Vector3(1.0, 0, 0);
rootGroup.getTransform().rotate = new Rn.Vector3(0, 1.0, 0.0);


// CameraComponent
const cameraControllerComponent = cameraEntity.getComponent(Rn.CameraControllerComponent);
cameraControllerComponent.setTarget(rootGroup);

// Env Map
const specularCubeTexture = new Rn.CubeTexture();
specularCubeTexture.baseUriToLoad = '../../../assets/ibl/specular/specular';
specularCubeTexture.mipmapLevelNumber = 10;
const diffuseCubeTexture = new Rn.CubeTexture();
diffuseCubeTexture.baseUriToLoad = '../../../assets/ibl/diffuse/diffuse';
diffuseCubeTexture.mipmapLevelNumber = 1;
const componentRepository = Rn.ComponentRepository.getInstance();
const meshRendererComponents = componentRepository.getComponentsWithType(Rn.MeshRendererComponent);
for (let meshRendererComponent of meshRendererComponents) {
meshRendererComponent.specularCubeMap = specularCubeTexture;
meshRendererComponent.diffuseCubeMap = diffuseCubeTexture;
}


Rn.CameraComponent.main = 0;
let startTime = Date.now();
const rotationVec3 = Rn.MutableVector3.one();
let count = 0;
const draw = function(time) {

if (p == null && count > 0) {
if (response != null) {

gl.enable(gl.DEPTH_TEST);
gl.viewport(0, 0, 600, 600);
gl.clearColor(0.8, 0.8, 0.8, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
}

p = document.createElement('p');
p.setAttribute("id", "rendered");
p.innerText = 'Rendered.';
document.body.appendChild(p);

}

if (window.isAnimating) {
const date = new Date();
const rotation = 0.001 * (date.getTime() - startTime);
//rotationVec3.v[0] = 0.1;
//rotationVec3.v[1] = rotation;
//rotationVec3.v[2] = 0.1;
const time = (date.getTime() - startTime) / 1000;
Rn.AnimationComponent.globalTime = time;
if (time > Rn.AnimationComponent.endInputValue) {
startTime = date.getTime();
}
//console.log(time);
// rootGroup.getTransform().scale = rotationVec3;
//rootGroup.getTransform().translate = rootGroup.getTransform().translate;
}

system.process();
count++;

requestAnimationFrame(draw);
}

draw();
}

document.body.onload = load;

10 changes: 10 additions & 0 deletions samples/test_e2e/Gltf2Importer/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test('regression test Gltf2Importer', async () => {
jest.setTimeout(60000);
const page = await browser.newPage();
await page.goto('http://localhost:8082/samples/test_e2e/Gltf2Importer');
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 60000});
const canvasElement = await page.$('#world');
const image = await canvasElement.screenshot();
expect(image).toMatchImageSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test('regression test TransformFeedbackInstancedDrawingWebGL2', async () => {
jest.setTimeout(60000);
const page = await browser.newPage();
await page.goto('http://localhost:8082/test/e2e/TransformFeedbackInstancedDrawing');
await page.goto('http://localhost:8082/samples/test_e2e/TransformFeedbackInstancedDrawing');
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 60000});
const canvasElement = await page.$('#world');
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test('regression test UBOInstancedDrawing', async () => {
jest.setTimeout(60000);
const page = await browser.newPage();
await page.goto('http://localhost:8082/test/e2e/UBOInstancedDrawing');
await page.goto('http://localhost:8082/samples/test_e2e/UBOInstancedDrawing');
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 60000});
const canvasElement = await page.$('#world');
Expand Down

0 comments on commit d6c3ad5

Please sign in to comment.