Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                

              
            
!

CSS

              
                body{
  margin: 0;
  background: #000;
}

canvas{
  display: block;
  margin: 0 auto;
}

              
            
!

JS

              
                //この関数に記述していく
var main = function(){
  //シーンの基本設定
  var scene = new THREE.Scene();
  var width = 600;
  var height = 400;
  var fov = 60;
  var aspect = width / height;//アスペクト比
  var near = 1;//ここから
  var far = 1000;//ここまでの間に3Dの描画を行う
  var camera = new THREE.PerspectiveCamera( fov, aspect, near, far);
  camera.position.set(0,0,10);//カメラの位置。ここでは10手前に引いている
  var controls = new THREE.OrbitControls(camera);

  if(!Detector.webgl) Detector.addGetWebGLMessage();
//レンダラーをDOM上に設置する
  var renderer = new THREE.WebGLRenderer({antialias:true});
  renderer.setClearColor(0x000000, 1);
  renderer.setSize( width,height );
  document.body.appendChild(renderer.domElement);

//光源を設定する
  var directionalLight = new THREE.DirectionalLight( 0xffffff);
  directionalLight.position.set( 0, 0.7, 0.7); //光源の角度
  scene.add(directionalLight);

//geometry(形状)とmaterial(素材)を元に物体(Mesh)を作成
  var geometry = new THREE.Geometry();
  geometry.vertices.push(new THREE.Vector3(0,0,4)); //頂点の作成
  geometry.vertices.push(new THREE.Vector3(2,0,0));
  geometry.vertices.push(new THREE.Vector3(0,-2,0));
  geometry.vertices.push(new THREE.Vector3(-2,0,0));
  geometry.vertices.push(new THREE.Vector3(0,2,0));
  geometry.vertices.push(new THREE.Vector3(0,0,-2));

  geometry.faces.push(new THREE.Face3(0,2,1)); //頂点を結んだ面の作成
  geometry.faces.push(new THREE.Face3(0,3,2));
  geometry.faces.push(new THREE.Face3(0,4,3));
  geometry.faces.push(new THREE.Face3(0,1,4));
  geometry.faces.push(new THREE.Face3(5,1,2));
  geometry.faces.push(new THREE.Face3(5,2,3));
  geometry.faces.push(new THREE.Face3(5,3,4));
  geometry.faces.push(new THREE.Face3(5,4,1));

  geometry.computeFaceNormals();//法線ベクトルの自動計算
  geometry.computeVertexNormals();//シェーディングを滑らかにする
//素材と形状からメッシュを作成
  var material = new THREE.MeshNormalMaterial();
  var mesh = new THREE.Mesh(geometry,material);
  scene.add(mesh);

  var wire = new THREE.MeshBasicMaterial({color: 0xffffff, wireframe: true});
  var wireMesh = new THREE.Mesh(geometry,wire);//同じ形状からワイヤーも作成
  scene.add(wireMesh);

  renderer.render(scene,camera);//これまでに作った内容をレンダリング

//作成したメッシュをアニメーションさせる
  (function renderLoop(){
    requestAnimationFrame(renderLoop);
    controls.update();
    mesh.rotation.set(
      0,
      mesh.rotation.y + 0.02,
      mesh.rotation.z + 0.02
    )
    wireMesh.rotation.set(
      0,
      mesh.rotation.y + 0.02,
      mesh.rotation.z + 0.02
    )
    renderer.render(scene,camera);
  })();
};

//関数mainをDOM構築完了後に読み込む
window.addEventListener('DOMContentLoaded',main,false);
              
            
!
999px

Console