Three.js THREEjs无法将sphree渲染到屏幕
嗨,我正在尝试让一个sphree渲染到屏幕上。这是我的js文件Three.js THREEjs无法将sphree渲染到屏幕,three.js,webgl,Three.js,Webgl,嗨,我正在尝试让一个sphree渲染到屏幕上。这是我的js文件 function Earth() { this.getEarth = init(); function init() { var map = {map:THREE.ImageUtils.loadTexture("images/earth_surface_2048.jpg")}; var material = new THREE.MeshBasicMaterial(map); var geometry
function Earth()
{
this.getEarth = init();
function init()
{
var map = {map:THREE.ImageUtils.loadTexture("images/earth_surface_2048.jpg")};
var material = new THREE.MeshBasicMaterial(map);
var geometry = new THREE.SphereGeometry(1,32,32);
return new THREE.Mesh(geometry, material);
}
function update()
{
getEarth.rotation.x += .01;
}
}
这是html文件中的脚本
页面中包含了threejs
<script>
var renderer = null;
var scene = null;
var camera = null;
var mesh = null;
var earth = null;
$(document).ready(
function() {
var container = document.getElementById("container");
renderer = new THREE.WebGLRenderer({ antialias: true } );
renderer.setSize(container.offsetWidth,container.offsetHeight);
container.appendChild(renderer.domElement)
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45,
container.offsetWidth / container.offsetHeight, 1, 4000 );
earth = new Earth();
scene.add(camera);
scene.add(earth.getEarth);
renderer.render( scene, camera );
}
);
</script>
var=null;
var-scene=null;
var-camera=null;
var-mesh=null;
var接地=零;
$(文件)。准备好了吗(
函数(){
var container=document.getElementById(“容器”);
renderer=new THREE.WebGLRenderer({antialas:true});
渲染器.setSize(container.offsetWidth,container.offsetSight);
container.appendChild(renderer.doElement)
场景=新的三个。场景();
摄像机=新的三个透视摄像机(45,
container.offsetWidth/container.offsetHeight,14000);
地球=新地球();
场景。添加(摄影机);
添加(earth.getEarth);
渲染器。渲染(场景、摄影机);
}
);
我从调试器中没有发现错误,所以有什么想法吗?earth.getEarth可能为null或函数。我记得scene.add()默默地忽略了它不能接受的东西,比如未定义的值等等
如何更改
var getEarth=init()
tothis.getEarth=init()代码>以便类范围外的代码将在地球对象中看到该变量。尽管我会建议不要对包含对象的变量使用像name这样的方法。刚才注意到了,我已经看到并更改了它,但它仍然不会呈现。你能设置一个JSFIDLE吗?JSFIDLE将是一个好主意。我想到的另一件事是,你的相机和地球似乎都在位置0,0,0,所以相机可能在你的地球几何体内部。默认情况下,面是单面的,从后面/里面看时它们是不可见的。您可以尝试更改相机或球体的位置和/或设置material.side=3。DoubleSide
,使球体的正面和背面都可见。Yaku谢谢您,我刚将相机设置为z=3,就看到了形状,thx allot!