2017-06-25 9 views
0

の内側に示されていないオブジェクト。このコードは黒いコンテナの中に赤い球を表示するはずですが、それは私のためではありません。 three.jsに慣れている人は、コードの何が間違っているのかを指摘していますか?three.js私はthree.jsを学んで起動するには、次のコードを使用していた容器

// Set the scene size. 
const WIDTH = 400; 
const HEIGHT = 300; 

// Set some camera attributes. 
const VIEW_ANGLE = 45; 
const ASPECT = WIDTH/HEIGHT; 
const NEAR = 0.1; 
const FAR = 10000; 

// Get the DOM element to attach to 
const container = 
    document.querySelector('#container'); 

// Create a WebGL renderer, camera 
// and a scene 
const renderer = new THREE.WebGLRenderer(); 
const camera = 
    new THREE.PerspectiveCamera(
     VIEW_ANGLE, 
     ASPECT, 
     NEAR, 
     FAR 
    ); 

const scene = new THREE.Scene(); 

// Add the camera to the scene. 
scene.add(camera); 

// Start the renderer. 
renderer.setSize(WIDTH, HEIGHT); 

// Attach the renderer-supplied 
// DOM element. 
container.appendChild(renderer.domElement); 

// Set up the sphere vars 
const RADIUS = 50; 
const SEGMENTS = 16; 
const RINGS = 16; 

// create the sphere's material 
const sphereMaterial = 
    new THREE.MeshLambertMaterial(
    { 
     color: 0xCC0000 
    }); 

// Create a new mesh with 
// sphere geometry 
const sphere = new THREE.Mesh(
    new THREE.SphereGeometry(
    RADIUS, 
    SEGMENTS, 
    RINGS), 
    sphereMaterial); 

// Move the Sphere back in Z so we 
// can see it. 
sphere.position.z = -300; 

// Finally, add the sphere to the scene. 
scene.add(sphere); 
+0

、いつどこであなたは '' renderer.render(シーン、カメラ)を呼び出していますか? – prisoner849

+0

上記のコードでは決してありません。しかし、renderer.render(シーン、カメラ)をコードの最後に追加すると、何も変わりません。まだ黒いコンテナエリア – D33Funky

答えて

1

あなたがTHREE.MeshLambertMaterial()を使用しているとして、あなたは、シーンに光源を追加するまで、あなたはこの材料でオブジェクトが表示されません。例えば

THREE.DirectionalLight()

var dirLight = new THREE.DirectionalLight(0xffffff); 
dirLight.position.set(100, 100, 100); 
scene.add(dirLight); 

jsfiddle例R86

+0

ありがとう!あなたはbookやthree.jsドキュメントの他のソースをお勧めできますか? – D33Funky

+1

:)すべての私の知識は試行錯誤の方法に基づいており、インターネットをサーフィンし、three.jsについて多くの異なる情報源を読んでいます。残念ながら、Lambert、Phong、またはStandard(およびその拡張子)のような素材を使用すると、公式文書には何の言及もありません。 – prisoner849

関連する問題