小编Var*_*yan的帖子

Three.js - 如何设置相对于对象的位置和方向的位置?

我试图让我的第二个对象位于我的第一个已旋转对象的正后方(-距离)。

假设我有 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 示例。不按比例

在此输入图像描述

javascript three.js

6
推荐指数
1
解决办法
4978
查看次数

HTML5 Canvas Javascript - 如何使用“translate3d”制作带有瓷砖的可移动画布?

我在使用可移动画布时遇到问题,该画布会随着“玩家”在地图上移动而进行调整。由于绘制 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)

html javascript canvas translate3d

5
推荐指数
1
解决办法
171
查看次数

Three.js - GLTF 模型位置不从原点开始

当我尝试加载带有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)

javascript three.js

2
推荐指数
1
解决办法
1607
查看次数

Node.js - 如何使用 package.json 运行多个服务器

尝试从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中使用

javascript node.js socket.io package.json

0
推荐指数
1
解决办法
77
查看次数

HTML CSS - 你能用 CSS 定义一个带有图像的类吗?

像这样的东西

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)

html css

0
推荐指数
1
解决办法
80
查看次数