【发布时间】:2020-01-07 19:51:06
【问题描述】:
我对 three.js 还很陌生,我似乎无法让我的场景(或相机)渲染。其他部分正在工作(我能够渲染我转换得很好的 adobe illustrator 矢量),但是如果我注释掉我的场景、相机和渲染器代码,它对浏览器中渲染的内容没有任何影响。
这是我的html:
<canvas id ="slot">
</canvas>
这是我的 js:
var c = document.getElementById('slot');
c.height = 282;
c.width = 400;
var cx = c.getContext('2d');
//This doesn't appear to be working ...
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000
);
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//Working just fine
cx.fillStyle="rgba(255,255,255,0)";
cx.fillRect(0,0,1,1);
cx.fillRect(1,0,1,1);
//....(goes on and on)
var slot = new THREE.Mesh(cx);
// GridHelper
var size = 10;
var divisions = 10;
var gridHelper = new THREE.GridHelper( size, divisions )
// Light
var light = new THREE.AmbientLight(0x404040);
// Fog
var fogColor = 0xFFFFFF;
var near = 10;
var far = 100;
var fog = new THREE.Fog(fogColor, near, far)
scene.add(slot, gridHelper, light, fog)
camera.position.z = 5;
renderer.render( scene, camera );
任何帮助将不胜感激
【问题讨论】:
-
有来自 f12 的消息吗?
-
@Ctznkane525 THREE.Object3D.add:对象不是 THREE.Object3D 的实例。
-
删除除three.js 设置内容之外的所有内容并插入多维数据集示例(threejs.org/docs/index.html#manual/en/introduction/…)并显示多维数据集,因此您评论的部分似乎不起作用,正在工作中。 @will 刚刚发布的错误是
THREE.Fog问题的结果,所以这可能是您问题的根源。 -
为什么在
THREE.Mesh构造函数中将画布上下文cx作为参数传递,而它需要几何图形和材质? -
@JDunken 谢谢。如果我注释掉我留下的雾代码: Uncaught TypeError: Cannot read property 'center' of undefined (指这一行) --> renderer.render(scene, camera);
标签: javascript three.js 3d data-visualization