首页
\
问答
\
Three.js Collada模型显示黑色,没有灯光直到鼠标移动(Three.js Collada model displayed black with no lights till a mouse movement)
Three.js Collada模型显示黑色,没有灯光直到鼠标移动(Three.js Collada model displayed black with no lights till a mouse movement)
我遇到了一个奇怪的问题,在三个显示collada模型。我怀疑脚本的逻辑有问题,但我无法弄清楚。 问题是Collada模型显示为黑色,直到用户移动鼠标(轨道控制)。 只有在此之后,模型才会被点亮。 因此,最初,当页面加载时,模型是黑色的,这使用户感到困惑。 代码有什么问题? 哪里可能是错误?
脚本的代码如下:
<script> if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); var container, stats; var camera, controls, scene, renderer; var pointLight; init(); render(); function animate() { pointLight.position.copy( camera.position ); requestAnimationFrame(animate); controls.update(); } function init() { camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 ); camera.position.set( -40, 70, 70 ); controls = new THREE.OrbitControls( camera ); controls.damping = 0.2; controls.addEventListener( 'change', render ); scene = new THREE.Scene(); // world var mesh; var loader = new THREE.ColladaLoader(); loader.load('./models/collada/test.dae', function (result) { mesh = result.scene; mesh.scale.set(0.3, 0.3, 0.3); scene.add(mesh); render(); }); // lights var hemLight = new THREE.HemisphereLight(0x000000, 0x303030, 0.8); scene.add(hemLight); pointLight = new THREE.PointLight( 0xffffff, 1.1 ); pointLight.position.copy( camera.position ); scene.add( pointLight ); // renderer renderer = new THREE.WebGLRenderer({antialias:true, alpha:true}); renderer.setClearColor(0xEEEEEE, 1); renderer.shadowMapType = THREE.PCFSoftShadowMap; renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight ); container = document.getElementById( 'container' ); container.appendChild( renderer.domElement ); window.addEventListener( 'resize', onWindowResize, false ); animate(); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); render(); } function render() { renderer.render( scene, camera ); } </script>
I've encountered one strange problem with displaying collada model in three.js I suspect that something wrong with the logic of the script but I can't figure out. The problem is that the Collada model is displayed black till a user moves a mouse (orbit controls). Only after this the model gets lighted. So, initially, when the page loads, the model is black and this is confusing a user. What's wrong with the code? Where could be the error?
The code of the script is the following:
<script> if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); var container, stats; var camera, controls, scene, renderer; var pointLight; init(); render(); function animate() { pointLight.position.copy( camera.position ); requestAnimationFrame(animate); controls.update(); } function init() { camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 ); camera.position.set( -40, 70, 70 ); controls = new THREE.OrbitControls( camera ); controls.damping = 0.2; controls.addEventListener( 'change', render ); scene = new THREE.Scene(); // world var mesh; var loader = new THREE.ColladaLoader(); loader.load('./models/collada/test.dae', function (result) { mesh = result.scene; mesh.scale.set(0.3, 0.3, 0.3); scene.add(mesh); render(); }); // lights var hemLight = new THREE.HemisphereLight(0x000000, 0x303030, 0.8); scene.add(hemLight); pointLight = new THREE.PointLight( 0xffffff, 1.1 ); pointLight.position.copy( camera.position ); scene.add( pointLight ); // renderer renderer = new THREE.WebGLRenderer({antialias:true, alpha:true}); renderer.setClearColor(0xEEEEEE, 1); renderer.shadowMapType = THREE.PCFSoftShadowMap; renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight ); container = document.getElementById( 'container' ); container.appendChild( renderer.domElement ); window.addEventListener( 'resize', onWindowResize, false ); animate(); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); render(); } function render() { renderer.render( scene, camera ); } </script>
原文:https://stackoverflow.com/questions/31649559
更新时间:2024-01-24 11:01
最满意答案
您可以在... ROOT / index.html文件中放置重定向,例如:
<head> <meta http-equiv="refresh" content="0;url=http://www.google.com"> </head>
You can place a redirect in the ...ROOT/index.html file, for example:
<head> <meta http-equiv="refresh" content="0;url=http://www.google.com"> </head>
相关问答
更多-
最简单的是拥有Tomcat主页 TOMCAT_HOME/webapps/ROOT/index.jsp 执行重定向到您要显示的起始页面或客户页面。 The easiest would be to have the Tomcat home page TOMCAT_HOME/webapps/ROOT/index.jsp perform a redirect to your start page or the custome page which you want to show.
-
Jekyll默认页面(Jekyll default page)[2022-04-11]
这不是真正的Jekyll问题,它更像是一个信息架构。 你的页面层次是这样的: |-index.html |-articles.html |-... 只要在index.html或index.md添加你想要的内容,如果你想用markdown写。 创建一个article.html或md页面,并在其中拷贝index.html的实际内容。 最后,如果您想在/articles/访问文章页面,只需在前面的内容中添加permalink: articles/ 。 否则,默认情况下会在articles.html达到。 Thi ... -
角度默认页面路由(Angular default page routing)[2022-05-01]
你可以使用状态路由,然后你可以使用statechangestart事件,例如: - .state('user.dashboard', { templateUrl: 'pages/my/dashboard/deshboard.html', controller: 'myDashboardController' url: '/dashboard', access: { loginRequired: true ... -
找到它,你需要首先进入Plesk Panael的主页,选择虚拟目录,然后选择你的域名,然后选择目录模式 Found it, you need first to go to your Home Page in Plesk Panael, choose virtual directories, then choose your domain, then choose Directory Propertories
-
Tomcat默认页面(Tomcat default page)[2023-03-23]
您可以在... ROOT / index.html文件中放置重定向,例如: You can place a redirect in the ...ROOT/index.html file, for example:Heather Solomon撰写的这篇文章(SharePoint MVP)将为您提供一些关于如何创建“布局”或更确切地说,母版页以及如何部署它们的有用提示: http : //www.heathersolomon.com/blog/文章/ servermstpageforsitecollect_feature.aspx This article by Heather Solomon (a SharePoint MVP) will give you some useful hints on how to c ...WebSphere AS默认页面(WebSphere AS default page)[2022-01-16]
在服务器的配置文件(如server.xml)中,您可以指定以禁用欢迎页面,然后将应用程序绑定到“/”上下文根。 这里有文档: http : //www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_config_httpDispatcher.html In your server's configuration ... 使用MVC更改默认页面(Change the Default page with MVC)[2023-10-06]
从ASP.NET中的URL Rooting(Web窗体) - chsakell的Blog ,在默认的MVC路由之前添加它: routes.MapPageRoute("default", "", "~/Default.aspx"); 您也可以使用过滤器完成此操作,但在HomeController的Index操作中进行重定向可能最简单。 public class HomeController : Controller { public ActionResult Index() { ...设置默认页面(Set Default Page)[2022-07-09]
开始 - >运行 - > inetmgr 单击您的站点 单击默认文档 添加whatevs应该是您的启动页面的名称 至于上面的评论,您是否更新了驱动器根目录中的“Web”文件或与.aspx页面位于同一位置的“Web”文件? Start --> Run --> inetmgr Click Your Site Click Default Document Add whatevs the name of your start-up page should be As far as your comment abov ...Struts 2默认页面(Struts 2 Default Page)[2022-08-27]
我的方法略有不同。 无论是Struts 2还是java都没关系。 只需在执行重定向的Web应用程序的根目录中添加index.html即可。 或者,您可以使用javascript。