请问,在three.js zhong 如何定义很多固定的三维的点放在空间中显示,我是小白,谢谢大家
init();
animate();
function init() {
//创建div,将其加入到页面中
container = document.createElement('div');
document.body.appendChild(container);
//定义相机
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);
camera.position.z = 10;
// 定义场景
scene = new THREE.Scene();
var ambient = new THREE.AmbientLight(0x101030);
scene.add(ambient);
var directionalLight = new THREE.DirectionalLight(0xffeedd);
directionalLight.position.set(0, 0, 1);
scene.add(directionalLight);
//定义材质
var PI2 = Math.PI*2;
var material = new THREE.SpriteCanvasMaterial({
color: 0xff0000,
program: function (context) {
context.beginPath();
context.arc(0, 0, 0.1, 0, PI2, true);
context.fill();
}
});
var i = 0;
for (var ix = 0; ix < count; ix++) {
particle = particles[i++] = new THREE.Sprite(material);
particle.position.x= ix;//具体的坐标点
particle.position.y= ix+1;
particle.position.z= ix+2;
scene.add(particle);
}
renderer = new THREE.CanvasRenderer();
// renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
document.addEventListener('mousemove', onDocumentMouseMove, false);
//
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild(stats.domElement);
window.addEventListener('resize', onWindowResize, false);
animate();
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function onDocumentMouseMove(event) {
mouseX = (event.clientX - windowHalfX) / 2;
mouseY = (event.clientY - windowHalfY) / 2;
}
//
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
camera.position.x += (mouseX - camera.position.x) * .5;
camera.position.y += (-mouseY - camera.position.y) * .5;
camera.lookAt(scene.position);
renderer.render(scene, camera);
}