Skip to content

Commit

Permalink
test: add canvas texture case
Browse files Browse the repository at this point in the history
  • Loading branch information
deepkolos committed Feb 28, 2021
1 parent 61985ec commit 34e260e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 46,886 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
three
tests/WaterBottle-*.glb
tests/*.bundle.js
tests/**/*.bundle.js
7 changes: 7 additions & 0 deletions config/rollup.config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export default [
file: `tests/memory/memory.bundle.js`,
},
},
{
input: `tests/texture/index.js`,
output: {
format: 'esm',
file: `tests/texture/index.bundle.js`,
},
},
];
19 changes: 19 additions & 0 deletions tests/canvas-texture/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<h3>测试 canvasTexture耗时</h3>
<script src="./index.bundle.js"></script>
</body>
</html>
48 changes: 48 additions & 0 deletions tests/canvas-texture/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as THREE from '../../build/three.module';
import { BrowserPlatform } from '../../src/BrowserPlatform/index';

THREE.PLATFORM.set(new BrowserPlatform());

const renderer = new THREE.WebGL1Renderer({ alpha: true });
const camera = new THREE.PerspectiveCamera(75, innerWidth / innerHeight, 0.1, 1000);
const scene = new THREE.Scene();
// const canvas = document.createElement('canvas');
// const ctx = canvas.getContext('2d');
// const canvasTexture = new THREE.CanvasTexture(canvas);

// const geometry = new THREE.BoxGeometry(1, 1, 1);
// const material = new THREE.MeshBasicMaterial({ map: canvasTexture });
// const box = new THREE.Mesh(geometry, material);

for (let i = 0; i < 100; i++) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const canvasTexture = new THREE.CanvasTexture(canvas);

const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ map: canvasTexture });
const box = new THREE.Mesh(geometry, material);

canvas.width = 2 ** 10;
canvas.height = 2 ** 10;
ctx.fillStyle = `rgb(${~~(Math.random() * 255)},${~~(Math.random() * 255)},${~~(Math.random() * 255)})`;
ctx.fillRect(0, 0, 2 ** 9, 2 ** 9);

box.position.set(Math.random(), Math.random(), -Math.random());

scene.add(box);
}

const render = () => {
requestAnimationFrame(render);
renderer.render(scene, camera);
};

document.body.appendChild(renderer.domElement);

renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(devicePixelRatio);

camera.position.z = 1;

render();
Loading

0 comments on commit 34e260e

Please sign in to comment.