编辑矩形几何顶点的正确方法是什么? [英] What is the correct way to edit the vertices of a box geometry?

查看:45
本文介绍了编辑矩形几何顶点的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在编辑许多盒形几何的顶点以创建唯一的形状,或修改几何的高度.它工作正常,我的场景看起来正确(这里有一个示例 http://imgur.com/sSx1bPk ).

So I'm editing the vertices of many box geometries to create unique shapes, or to modify the heights of the geometries. It works fine and my scenes look correct (here's an example http://imgur.com/sSx1bPk).

但是,当我使用 ObjectExporter 并尝试将场景加载到 http://threejs.org/editor/,我的顶点更改均不存在.另外,当我尝试将 scene.json 文件加载到Blender中时,出现一个错误(我似乎无法复制/粘贴),其中列出了 KeyError:'vertices'

However, when I use the ObjectExporter and try to load the scene into http://threejs.org/editor/, none of my vertex changes are present. Also when I try to load the scene.json file into blender, I get an error (which I can't seem to copy/paste) which lists KeyError:'vertices'

基本上,我构建了一个UI来编辑任何盒子几何的顶点,然后将这些编辑保存到矩阵中,然后在加载场景时交叉检查该矩阵.我的功能看起来像这样

Basically, I built a UI to edit the vertices of any box geometry, I save these edits into a matrix, then cross check that matrix when loading the scene. My function looks like this

setBaseTileVertices:function()
{
    var scope = this;

    scope.baseTiles.children.forEach(function(tile , t)
    {
        tile.geometry.vertices.forEach(function(vertex , v)
        {
            vertex.x = (tile.userData.vertices[v].x) ? tile.userData.vertices[v].x : vertex.x;
            vertex.y = (tile.userData.vertices[v].y) ? tile.userData.vertices[v].y : vertex.y;
            vertex.z = (tile.userData.vertices[v].z) ? tile.userData.vertices[v].z : vertex.z;
        });
    });
}

是否还有其他更正确的方式来编辑顶点,以便编辑器和/或Blender能够识别更改?我在使用正确的出口商吗?我尝试使用 THREE.SceneExporter ,但出现了如下所示的错误

Is there some other more correct way to edit vertices so that the changes will be recognised by the editor and/or Blender? Am I using the right exporter? I tried used the THREE.SceneExporter but got errors as indicated here Three.js SceneExporter getting Uncaught Syntax error

修改

经过一番调查,我发现在输出JSON中,我所有的盒子几何形状都具有相似的矩阵值,而我创建的方形金字塔具有正确的矩阵.我想我在修改每个几何图形时需要更新它们的矩阵.不太确定如何立即执行此操作,但我认为我的工作方向正确.

After a bit of investigation, I've seen that in my output JSON, all my box geometries have a similar matrix value, while a square pyramid I created has the correct matrix. I guess I need to update the matrix of each geometry when I modify it. Not too sure how to do that right now but I think I'm on the right track.

编辑2

我的每个几何的矩阵似乎都在更新,所以我不知道现在发生了什么.我创建的金字塔可以很好地渲染,但是所有盒子的几何形状都变得平坦,顶点不变.这是一个在编辑器中的外观示例 http://imgur.com/oGury4e 注意边界框帮助程序知道 baseTiles 的高度,它是包含每个图块的 Object3D .仅当将其编辑的顶点考虑在内时,它才能知道这一点.

Well it seems like the matrices for each of my geometries are getting updated, so I don't know what's going on now. The pyramid I've created renders fine, but all the box geometries just become flat, with no change to their vertices. Here's an example of how it looks in the editor http://imgur.com/oGury4e note that the bounding box helper knows the height of baseTiles which is an Object3D that contains each tile. It can only know this if its factoring in their edited vertices.

编辑3

因此,我进行了测试,并修改了 ObjectExporter.js 的第65-74行,以便它们现在可以读取

So I've done a test and modified lines 65 - 74 of ObjectExporter.js so that they now read

} else if ( geometry instanceof THREE.BoxGeometry ) {

    data.type = 'Geometry';
    data.data = geometryExporter.parse( geometry );

    delete data.data.metadata;

    //handleParameters( [ 'width', 'height', 'depth', 'widthSegments', 'heightSegments', 'depthSegments' ] );}

现在我的水平仪在编辑器中的形状看来是正确的 http://imgur.com/IDlYCJ6 但是,好像我的颜色或材料没有被翻译过来吗?一切都是黑色,而几何图形的+ Y面应被涂成绿色.

Now my level looks correct in terms of shape in the editor http://imgur.com/IDlYCJ6 however, seems like my colours or materials are not getting translated over? Everything is black, whereas the +Y faces of the geometries should be coloured green.

根据要求,下面是使用未经编辑的ObjectExporter导出的示例

As requested here's an example from exporting with the non-edited ObjectExporter

{
    "metadata": {
        "version": 4.3,
        "type": "Object",
        "generator": "ObjectExporter"
    },
    "geometries": [{
        "uuid": "25437534-318D-4BB9-9E97-207E390F1A8D",
        "type": "BoxGeometry",
        "width": 64,
        "height": 32,
        "depth": 64
    }],
    "materials": [{
        "type": "MeshFaceMaterial",
        "materials": [{
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "BCFDD918-A69C-4443-806A-A46E356C272C",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "4969265D-D0B2-4E4A-A60A-AB20EC541FD5",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "141153C7-C284-4120-9DB9-8386F4C90496",
            "type": "MeshBasicMaterial",
            "color": 6127158,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "B2CDDAE4-B690-41F7-84EC-377C73A7FF21",
            "type": "MeshBasicMaterial",
            "color": 6127158,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "0B21CD67-D4FA-447E-9CA1-56CA755C0872",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "3089DC93-85E8-42CD-BBE9-2D2A45441AB2",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }]
    }],
    "object": {
        "uuid": "DE6BC181-ECA5-4B7A-85EA-64387C8B04E1",
        "name": "tile_5_10",
        "type": "Mesh",
        "geometry": "25437534-318D-4BB9-9E97-207E390F1A8D",
        "matrix": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 640, 0, 320, 1]
    }
}

这是我编辑的JSON示例(它是一个不同的对象,因此某些值可能会有所不同)(框几何被解析为几何,如果我像这样解析整个场景,它给出的结果 http://imgur.com/IDlYCJ6 )

And here is an example of the JSON (it's a different object so some values may be different) with my edits (box geometry is parsed as geometry, if I parse the entire scene like this, it gives this result http://imgur.com/IDlYCJ6)

{
    "metadata": {
        "version": 4.3,
        "type": "Object",
        "generator": "ObjectExporter"
    },
    "geometries": [{
        "uuid": "4E8EFB7F-8225-4EAA-AE69-C25B23DDE642",
        "type": "Geometry",
        "data": {
            "vertices": [32, 88, 32, 32, 88, -32, 32, -16, 32, 32, -16, -32, -32, 112, -32, -32, 112, 32, -32, -16, -32, -32, -16, 32],
            "normals": [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1],
            "uvs": [
                [0, 1, 0, 0, 1, 1, 1, 0]
            ],
            "faces": [56, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 56, 2, 3, 1, 1, 3, 2, 0, 0, 0, 0, 56, 4, 6, 5, 0, 1, 2, 1, 1, 1, 1, 56, 6, 7, 5, 1, 3, 2, 1, 1, 1, 1, 56, 4, 5, 1, 0, 1, 2, 2, 2, 2, 2, 56, 5, 0, 1, 1, 3, 2, 2, 2, 2, 2, 56, 7, 6, 2, 0, 1, 2, 3, 3, 3, 3, 56, 6, 3, 2, 1, 3, 2, 3, 3, 3, 3, 56, 5, 7, 0, 0, 1, 2, 4, 4, 4, 4, 56, 7, 2, 0, 1, 3, 2, 4, 4, 4, 4, 56, 1, 3, 4, 0, 1, 2, 5, 5, 5, 5, 56, 3, 6, 4, 1, 3, 2, 5, 5, 5, 5]
        }
    }],
    "materials": [{
        "type": "MeshFaceMaterial",
        "materials": [{
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "E1E6A4F7-06B0-41E2-8131-F2E103D8F7F7",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "7D777F70-D279-4112-AD6F-FBAFCE1EE9E2",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "5BBC767A-F130-4F4D-8A5C-489C40D2F698",
            "type": "MeshBasicMaterial",
            "color": 6127158,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "F4F167E2-013E-4A6A-B7F1-80246DD15023",
            "type": "MeshBasicMaterial",
            "color": 6127158,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "CA2ADC0E-F20B-485B-B5D3-DE9B58A733B0",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }, {
            "metadata": {
                "version": 4.2,
                "type": "material",
                "generator": "MaterialExporter"
            },
            "uuid": "7BC988E6-B3A0-4BF2-B360-1C0F4976436F",
            "type": "MeshBasicMaterial",
            "color": 0,
            "opacity": 1,
            "transparent": false,
            "wireframe": false
        }]
    }],
    "object": {
        "uuid": "809D131E-3F34-4DCB-8304-EDCA144BF1A6",
        "name": "tile_9_9",
        "type": "Mesh",
        "geometry": "4E8EFB7F-8225-4EAA-AE69-C25B23DDE642",
        "matrix": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 576, 0, 576, 1]
    }
}

有什么想法吗?

推荐答案

经过大量研究,我发现当前正确的方法是将 BoxGeometry 对象转换为 BufferGeometry 或常规的 Geometry 对象.您可以在编辑其顶点后执行此操作.

After a bunch of research, I've found that currently, the correct way to do this is to convert your BoxGeometry objects to BufferGeometry or regular Geometry objects. You can do this after editing their vertices.

像这样

var box = new THREE.BoxGeometry(64 , 32 , 64);

box.verticesNeedUpdate = true;
box.vertices[0].y = 128;
box.vertices[1].y = 128;

var geometry = new THREE.BufferGeometry().fromGeometry(box);

//or alternatively

var geometry = new THREE.Geometry();
geometry.merge(box);

现在,如果使用 ObjectExporter 导出对象,则应将其加载到 http://threejs.org/editor 很好.

Now, if you export the object using the ObjectExporter it should load into http://threejs.org/editor fine.

这篇关于编辑矩形几何顶点的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆