我试图让我的第二个对象位于我的第一个已旋转对象的正后方(-距离)。
假设我有 2 个对象:
var object1 = new THREE.Object3D();
object1.position.set(5, 10, 53);
object1.rotateX(1);
object1.rotateY(1.5);
var distance = 20; //place object2 20 units behind object1
var object2 = new THREE.Object3D();
object2.position.set( /*position object2 right behind object1 -distance */);
object2.lookAt(object1);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何object2直接将其放置在object1已旋转的后面?
视觉 2D 示例。不按比例
我在使用可移动画布时遇到问题,该画布会随着“玩家”在地图上移动而进行调整。由于绘制 600 个瓷砖,每秒 60 次非常低效,我切换到使用translate3d并且只有draw在玩家越过一个完整的瓷砖时 - 但它一直出现故障并且不能平滑地移动。我将如何正确实现这一目标?
const ctx = canvas.getContext('2d');
canvas.height = 200;
canvas.width = 600;
const tileSize = canvas.height/6;
const MAIN = {position:{x: 120, y: 120}};
const canvasRefresh = {x: 0, y: 20};
document.body.onmousemove = e => MAIN.position = {x: e.clientX, y: e.clientY};
const tiles = {x: 20, y: 20}
function update(){
moveMap();
requestAnimationFrame(update);
}
function drawMap(){
for(var i = 0; i < tiles.x; i++){
for(var j = 0; j < tiles.y; j++){
ctx.fillStyle …Run Code Online (Sandbox Code Playgroud)当我尝试加载带有0,0,0位置的 glTF 模型时,它距离原点很远。
当我尝试旋转 glTF 模型时,它围绕原点(用蓝点标记)旋转,而不是从中心旋转。
我认为这是某种关键问题?
我该如何解决?
var tree;
function loadGLTFCharacter(path, position){
// Load a glTF resource
loader.load(
// resource URL
path,
// called when the resource is loaded
function ( gltf ) {
gltf.scene.traverse( function( node ) {
if ( node.isMesh ) {
node.castShadow = true;
node.receiveShadow = true;
}
} );
gltf.scene.position.set(position.x, position.y, position.z);
tree = gltf.scene;
scene.add( tree );
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Group
gltf.scenes; // Array<THREE.Group>
gltf.cameras; // Array<THREE.Camera>
gltf.asset; // Object …Run Code Online (Sandbox Code Playgroud) 尝试从package.json. 此方法仅运行server1.js,但忽略server2.js
包.json
{
"name": "demo",
"version": "1.0.0",
"description": "demo",
"main": "server1.js",
"dependencies": {
"express": "^4.14.0",
"socket.io": "^1.5.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server1.js && node server2.js",
}
}
Run Code Online (Sandbox Code Playgroud)
PS——代码将在AWS中使用
像这样的东西
HTML
<button class="img">This button has an image</button>
<button class="img">This button has the same image</button>
Run Code Online (Sandbox Code Playgroud)
CSS
.img {
url: '/testimage.png'
}
Run Code Online (Sandbox Code Playgroud) javascript ×4
html ×2
three.js ×2
canvas ×1
css ×1
node.js ×1
package.json ×1
socket.io ×1
translate3d ×1