简体   繁体   English

应用three.js细分修饰符而不改变外部几何?

[英]Apply three.js subdivision modifier without changing outer geometry?

I am trying to take any three.js geometry and subdivide its existing faces into smaller faces.我正在尝试采用任何three.js几何并将其现有面细分为较小的面。 This would essentially give the geometry a higher "resolution".这基本上会给几何图形一个更高的“分辨率”。 There is a subdivision modifier tool in the examples of three.js that works great for what I'm trying to do, but it ends up changing and morphing the original shape of the geometry. Three.js 的示例中有一个细分修改器工具,它非常适合我想要做的事情,但它最终会改变和变形几何的原始形状。 I'd like to retain the original shape.我想保留原来的形状。

View the Subdivision Modifier Example 查看细分修改器示例


Example of how the current subdivision modifier behaves:当前细分修饰符的行为示例:

在此处输入图片说明

Rough example of how I'd like it to behave:我希望它如何表现的粗略示例:

在此处输入图片说明


The subdivision modifier is applied like this:细分修饰符的应用如下:

let originalGeometry = new THREE.BoxGeometry(1, 1, 1);
let subdivisionModifier = new THREE.SubdivisionModifier(3);
let subdividedGeometry = originalGeometry.clone();
subdivisionModifier.modify(subdividedGeometry);

I attempted to dig around the source of the subdivision modifier , but I wasn't sure how to modify it to get the desired result.我试图挖掘细分修饰符来源,但我不确定如何修改它以获得所需的结果。

Note: The subdivision should be able to be applied to any geometry.注意:细分应该能够应用于任何几何体。 My example of the desired result might make it seem that a three.js PlaneGeometry with increased segments would work, but I need this to be applied to a variety of geometries.我的预期结果示例可能会使具有增加段的three.js PlaneGeometry 看起来可行,但我需要将其应用于各种几何图形。

Based on the suggestions in the comments by TheJim01, I was able to dig through the original source and modify the vertex weight, edge weight, and beta values to retain the original shape.根据 TheJim01 评论中的建议,我能够挖掘原始来源并修改顶点权重、边权重和 beta 值以保留原始形状。 My modifications should remove any averaging, and put all the weight toward the source shape.我的修改应该删除任何平均,并将所有权重放在源形状上。

There were three sections that had to be modified, so I went ahead and made it an option that can be passed into the constructor called retainShape , which defaults to false.有三个部分必须修改,所以我继续将其设置为一个选项,可以将其传递到名为retainShape的构造retainShape ,该构造函数默认为 false。

I made a gist with the modified code for SubdivisionGeometry.js.我用修改后的 SubdivisionGeometry.js 代码做了一个要点。

View the modified SubdivisionGeometry.js Gist 查看修改后的 SubdivisionGeometry.js Gist


Below is an example of a cube being subdivided with the option turned off, and turned on.下面是在关闭和打开该选项的情况下细分立方体的示例。

Left: new THREE.SubdivisionModifier(2, false);左: new THREE.SubdivisionModifier(2, false);

Right: new THREE.SubdivisionModifier(2, true);右: new THREE.SubdivisionModifier(2, true);

在此处输入图片说明

If anyone runs into any issues with this or has any questions, let me know!如果有人遇到任何问题或有任何疑问,请告诉我!

The current version of three.js has optional parameters for PlaneGeometry that specify the number of segments for the width and height;目前的three.js 版本有PlaneGeometry 的可选参数,用于指定宽度和高度的段数; both default to 1. In the example below I set both widthSegments and heightSegments to 128. This has a similar effect as using SubdivisionModifier.两者都默认为 1。在下面的示例中,我将 widthSegments 和 heightSegments 都设置为 128。这与使用 SubdivisionModifier 的效果类似。 In fact, SubdivisionModifier distorts the shape, but specifying the segments does not distort the shape and works better for me.事实上,SubdivisionModifier 会扭曲形状,但指定线段不会扭曲形状,对我来说效果更好。

var widthSegments = 128;
var heightSegments = 128;
var geometry = new THREE.PlaneGeometry(10, 10, widthSegments, heightSegments);
//    var geometry = new THREE.PlaneGeoemtry(10,10); // segments default to 1
//    var modifier = new THREE.SubdivisionModifier( 7 );
//    geometry = modifier.modify(geometry);

https://threejs.org/docs/#api/en/geometries/PlaneGeometry https://threejs.org/docs/#api/en/geometries/PlaneGeometry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM