ThreeJS - Extrude ParametricGeometry

时间:2018-02-22 12:04:47

标签: javascript three.js geometry

有没有办法将ExtrudeGeometry与ParametricGeometry一起使用?
像这样:

function exampleGeometryF(u,v){
  var x = -(width/2) + width * u;
  var y = -(height/2) + height *v;
  var z = (Math.sin(u*Math.PI))* -20;
  return new THREE.Vector3(x,y,z);
}

let parametricGeometry = new THREE.ParametricGeometry(exampleGeometryF, 100, 100);
let extrudedGeometry = new THREE.ExtrudeGeometry(parametricGeometry, {amount:10, ...});

因此,本例中的parametricGeometry描述了平面,如 Geometry。现在我想给这个几何学一个深度。 欢迎解决方法!

1 个答案:

答案 0 :(得分:0)

特别是对于具有一些“深度”的类平面几何体,您可以变形框几何体:

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.setScalar(3);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

var controls = new THREE.OrbitControls(camera, renderer.domElement);

var boxGeom = new THREE.BoxGeometry(2, 2, 3, 10, 10, 1);
boxGeom.vertices.forEach(v => {
  v.z += Math.cos(v.x * 2) * Math.sin(v.y * 2) * 0.125;
});

var deformed = new THREE.Mesh(boxGeom, new THREE.MeshBasicMaterial({
  color: "aqua",
  wireframe: true
}));
scene.add(deformed);

render();

function render() {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}
body {
  overflow: hidden;
  margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/90/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>