Skip to content

Instantly share code, notes, and snippets.

@ikeryou
Created September 8, 2016 00:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikeryou/0b5d8e6302888247e70335a8309dade2 to your computer and use it in GitHub Desktop.
Save ikeryou/0b5d8e6302888247e70335a8309dade2 to your computer and use it in GitHub Desktop.
three.js初期化 主に2D系
// カメラ
var camera = new THREE.OrthographicCamera();
// レンダラー
// id=mainのcanvasタグ指定
var renderer = new THREE.WebGLRenderer({
antialias: false,
canvas: document.getElementById('main')
});
renderer.setPixelRatio(window.devicePixelRatio || 1);
// メインのscene
var scene = new THREE.Scene();
// -------------------------
// 画面のリサイズ時に実行
// -------------------------
function _resize() {
// ステージサイズ
w = 1000;
h = 1000;
// カメラの設定
camera.left = -w * 0.5
camera.right = w * 0.5
camera.top = h * 0.5
camera.bottom = -h * 0.5
camera.near = 0.1
camera.far = 1000
camera.zoom = 1
camera.updateProjectionMatrix()
camera.position.set(0, 0, 1)
camera.lookAt(new THREE.Vector3(0, 0, 0))
renderer.setSize(w, h);
}
// -------------------------
// 画面の更新時に実行
// -------------------------
function _update() {
renderer.setClearColor(new THREE.Color(0xffffff));
renderer.render(scene, camera);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment