Browse Source

使用color设置背景颜色

master
blobt 4 years ago
parent
commit
7ac37a2b28
  1. 6
      src/index.js

6
src/index.js

@ -7,7 +7,7 @@ var scene = new THREE.Scene();
//创建模型和material //创建模型和material
var geometry = new THREE.BufferGeometry(); var geometry = new THREE.BufferGeometry();
var vertices = new Float32Array([ var vertices = new Float32Array([
0, 0, 100
0, 0, 0
]); ]);
var posAttribute = new THREE.BufferAttribute(vertices, 3); var posAttribute = new THREE.BufferAttribute(vertices, 3);
//类型数组创建顶点颜色color数据 //类型数组创建顶点颜色color数据
@ -17,8 +17,6 @@ var posAttribute = new THREE.BufferAttribute(vertices, 3);
var colorAttribute = new THREE.BufferAttribute(colors, 3); var colorAttribute = new THREE.BufferAttribute(colors, 3);
geometry.attributes.position = posAttribute; geometry.attributes.position = posAttribute;
geometry.attributes.color = colorAttribute; geometry.attributes.color = colorAttribute;
var material = new THREE.PointsMaterial( { var material = new THREE.PointsMaterial( {
vertexColors: THREE.VertexColors, vertexColors: THREE.VertexColors,
size: 10.0 //点对象像素尺寸 size: 10.0 //点对象像素尺寸
@ -50,7 +48,7 @@ camera.lookAt(scene.position);
//创建渲染器 //创建渲染器
var renderer = new THREE.WebGLRenderer(); var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight); renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xb9d3ff, 1); //设置背景颜色
renderer.setClearColor("rgb(30, 30, 30)", 1); //设置背景颜色
document.body.appendChild(renderer.domElement); document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement); const controls = new OrbitControls(camera, renderer.domElement);

Loading…
Cancel
Save