簡體   English   中英

Three.js中的插值曲面

[英]Interpolated surface in Three.js

嗨伙計,

在Three.js中,我有一個問題areigig曲面:我有一堆Vec3點,想通過它們插入曲面。 在搜索時,我跨過貝塞爾曲線( Three.js貝塞爾曲線 ,僅作為線條),看起來更像是我在搜索: three.js Nurbs 我試圖重新構造代碼,但是文檔太糟糕了(類似這樣的頁面),並且通過重新構造代碼我並沒有了解所有工作原理……

因此,這里的問題是:有什么簡單的方法可以從計算出的點中獲取形狀? (如果不進行插值,我仍然會很高興)。

感謝大伙們!

編輯:我要實現的是一個表面圖。 我腳在http://acko.net/blog/making-mathbox/上,但是它太大了,無法滿足我的需求...

經過一番嘗試和錯誤后,我找到了一個解決方案:添加一個平面,然后轉換單個頂點。

// need to setup 'step', 'xStart', 'xEnd', 'yStart', 'yEnd'

// calc the variables
var width = Math.abs(-xStart+xEnd),
    height = Math.abs(-yStart+yEnd);

var stepsX = width*step, stepsY = height*step;

var posX = (xStart+xEnd)/2;
var posZ = (yStart+yEnd)/2;

// add a plane and morph it to a function
var geometry = new THREE.PlaneGeometry( width, height, stepsX - 1, stepsY - 1 );
geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );

var size = stepsX * (stepsY), 
    data = new Float32Array( size );

var count = 0, scope = {};

mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial( { 
    side : THREE.DoubleSide,
    transparent: true,
    shading: THREE.SmoothShading,
    opacity : _opacity }));


mesh.updateMatrixWorld();

// calc y value for every vertice
for ( var i = 0; i < size; i ++ ) {
    // calculate the current values
    // http://stackoverflow.com/questions/11495089/how-to-get-the-absolute-position-of-a-vertex-in-three-js
    var vector = mesh.geometry.vertices[i].clone();
    vector.applyMatrix4( 
        mesh.matrixWorld
        );
    // set them into the scope
    scope.x = vector.x + posX;
    scope.y = vector.z + posZ;
    // calculate point and write it in a temp array
    data[i] = math.eval(term, scope);
}

// push the new vertice data
for ( var i = 0, l = geometry.vertices.length; i < l; i ++ ) {
    geometry.vertices[ i ].y = data[ i ];
}

// update the new normals
geometry.computeFaceNormals();
geometry.computeVertexNormals();

// add to scene
scene.add( mesh );

唯一的問題是它不適用於tan(x)類的非靜態函數。 此代碼段使用math.js計算該術語。

問候墊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM