Creating 3D shapes with ExtrudeParametricGeometry in ThreeJS

Is it possible to combine ExtrudeGeometry with ParametricGeometry?
For example:

function customGeometryFunction(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(customGeometryFunction, 100, 100);
let extrudedGeometry = new THREE.ExtrudeGeometry(parametricGeometry, {amount:10, ...});

In this scenario, the parametricGeometry represents a plane-like geometry. The objective is to add depth to this geometry. Any suggestions or workarounds are appreciated!

Answer №1

When dealing with a plane-like structure that has some depth to it, one approach is to manipulate the geometry of a box:

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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fb.UI Dialogs now appearing in Popups rather than an iframe (part 2)

Here is a related issue that I came across: With the assistance of OffBySome, I managed to display my FB.ui dialog boxes in an iframe rather than as pop-ups. However, now I am experiencing an issue where the dialog appears but the loading throbber continu ...

JavaScript and .NET Core: Implementing file uploads without the use of FormData or FromFrom

Currently attempting to create a "basic" file upload feature. Utilizing JavaScript on the frontend and .NET Core on the backend. Previously, I had successfully implemented FormData / multipart, FromForm, and iFormFile. However, I have been advised agains ...

Obtain the URL for a Facebook Page or Profile

In the process of creating an application, I am incorporating a feature that allows users to enter their profile URLs for various social networks like Facebook, Twitter, and Google+. For now, let's focus on Facebook. To simplify the process of inputt ...

Using Node.js and React to dynamically render a different HTML file in response to a request

We are currently working on implementing AMP pages for our project. Our current solution involves detecting a query in the URL, such as: myurl.com?amp=1, and completely redrawing the page with the necessary markup. However, our server is set up to choose ...

Exploring the concept of event delegation: Understanding the difference between Event.target and

In the MDN Event.target reference, there is an example provided regarding event delegation: Example of Event Delegation // Assuming there is a 'list' variable containing an instance of an // HTML ul element. function hide(e) { // Unless l ...

What techniques can I employ in Angular to develop engaging widgets using plain HTML, without any Angular-specific elements?

I am currently developing a cutting-edge Angular application that serves as a training platform to offer online courses to users. Each course is essentially a set of "slides," which are HTML partials through which the user can navigate in order. These sli ...

Understanding the purpose of the meshPerAttribute parameter in an InstancedBufferAttribute in Three.js

I'm puzzled about the purpose of the meshPerAttribute argument in a Three.js InstancedBufferAttribute [documentation]. What exactly does the meshPerAttribute argument signify? I've noticed that the value provided for this argument is consistently ...

What is a method to omit elements within a nested child element from a selection without relying on the children() function

Here is an example of an element: <div id="foo"> <a href="#" class="some">click me</a> <div id="bar"> <a href="#" class="some">click me too</a> </div> </div> I am facing the challenge of selectin ...

Tips for displaying the html content saved in the database onto an ejs webpage

This task seems simple, but I'm struggling to solve it. In my Node.js/Express webapp, I have the Quill.js editor installed. It stores my description in MySQL DB like this: <p><strong>This is the quill data. How are we doing dev?</stron ...

No output is displayed in the absence of errors. The program is functioning correctly

app.js angular.module('app', ['ionic', 'ui.router']) .config(('$urlRouterProvider', '$stateProvider', function($urlRouterProvider,$stateProvider){ $urlRouterProvider.otherwise('/'); $sta ...

The maximum size for MongoDB documents is restricted to 16 megabytes

When referring to Document, is it talking about the complete document collection or the individual documents within the collection? A similar question was posed on Stack Overflow: Mongodb collection maximum size limit? However, I am having trouble graspi ...

Is there a way to store a blob URL as a (.webm) video on my server using a combination of JavaScript and PHP

I have integrated RecordRTC for screen recording, Here is the code snippet I am using: <html> <head> <style> html, body { margin: 0!important; padding: 0!important; text-align: center; font-family: ...

Integrating Amazon external images in NextJS

There is a specific issue with loading images from a URL stored on Amazon S3 within the domain configured in next.config.js. Strangely, when using external URLs like Unsplash, the images load fine. The problematic URL is: idinheiro-admin-images.s3.sa-east ...

Retrieving data from a JSON file using JavaScript in a Node.js environment

Seeking help to extract a value from a JSON file in JavaScript but struggling to find the right syntax. If someone could assist me with writing this line of code in Node.js, I would greatly appreciate it. The value I am trying to retrieve is "totalCount". ...

Tips on preventing right-click actions in jqGrid

While utilizing onSelectRow in a jqGrid, I have noticed that it functions properly when clicking with the left mouse button. However, when right-clicking, it still triggers the function. My aim is for the right-click to perform its usual action (such as di ...

Issue with React video element not pausing

Hey there, I've been working on creating a custom video player in React and have encountered an issue. I'm trying to use the handlePlay function as an onClick event to play or pause the video. The state variable isPlaying is used to track the use ...

Using the same module in multiple files

Incorporating Underscore.js into my project involves including this line of code in nearly every file: var _ = require('underscore'). Since the require function is synchronous, it loads the same file repeatedly. Could this impact performance? A ...

Challenge encountered while adding child nodes to jqtree following a successful ajax call

Having some trouble with adding child nodes to the tree. The situation is this: I need to load tree nodes when clicking on a node arrow using an ajax call. Initially, I am passing only the root level nodes to the tree and everything works fine. However, wh ...

Converting a text file to JSON in TypeScript

I am currently working with a file that looks like this: id,code,name 1,PRT,Print 2,RFSH,Refresh 3,DEL,Delete My task is to reformat the file as shown below: [ {"id":1,"code":"PRT","name":"Print"}, {" ...

Firefox causing issues with Rails Ajax functionality

My Rails application includes an AJAX call that currently triggers a JavaScript alert message. While this functionality works smoothly on Safari and Chrome, it strangely fails to function on Firefox (across all its recent versions). I tried debugging the c ...