【发布时间】:2014-07-06 16:09:59
【问题描述】:
我正在尝试将three.js 入门指南中的基本旋转立方体示例加载到基本流星应用程序中: http://threejs.org/docs/index.html#Manual/Introduction/Creating_a_scene
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);
var geometry = new THREE.CubeGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
var render = function () {
requestAnimationFrame(render);
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render(scene, camera);
};
I have added this code into a template js manager file of a new meteor app and then call the render function on the render of my template:
Template.hello.rendered = function() {
if (!this._rendered) {
this._rendered = true;
render();
}
}
My template
<template name="hello">
<head>
<title>My first Three.js app</title>
<style>canvas { width: 100%; height: 100% }</style>
</head>
<body>
</body>
</template>
我通过以下方式从 atomosphere 添加了三个.js: mrt加三 并将包成功加载到我的应用程序中 但是,当我启动流星时,我收到一个错误,即 THREE 未定义。 我曾尝试将three.js 移动到lib 文件夹中,但没有奏效,因为我收到“self”未定义的错误。我认为这应该只作为客户端库加载。我曾尝试将它与客户端文件夹放在我的管理器文件下方,但这似乎也不起作用,而且看起来很hacky。似乎应该先加载陨石安装包,对吧?为什么我的模板管理器不提供此功能?
任何帮助将不胜感激。我对流星和three.js都是新手,所以我认为让这个基本演示工作真的会让我大开眼界。 谢谢!
【问题讨论】:
-
非常感谢您的回复。我没有运气就试了一下。我仍然收到“未定义三个”的错误。我最初在我的原始项目中尝试在该文件夹中安装 min.three.js 包。我还尝试创建一个没有安装 three.js 气氛包的新应用程序,以确保它不会导致问题。在这两种情况下,我都会收到“未定义三个”的错误。我不明白为什么我的模板管理器不能使用三个。