Ways to implement variable face sizes in three.js meshes

Recently, I dove into the world of three.js and started playing around with it. I've been pondering whether there's a way to add some randomness to the size of the faces in a mesh created from their existing geometries.

While three.js is fantastic for low-poly work, the symmetry of the meshes it generates can sometimes detract from the desired effect. I'm on a quest to figure out how to give each face a unique size, maybe even throw in some jitter or rotation to create a more "handcrafted" appearance, if you will.

I had the inkling that math.random could be the key, but as a newcomer to JavaScript, I find myself unsure how to implement it.

Displayed below is the code snippet for the object I wish to imbue with a more organic look:

function createObject() {
    var geometry = new THREE.SphereGeometry(70, 31, 17);
    var material = new THREE.MeshPhongMaterial({
        color:Colors.blue, 
        shading:THREE.FlatShading
    });
    var sphere = new THREE.Mesh(geometry, material);
    sphere.position.set(45,100,0);
    sphere.castShadow = true;
    sphere.receiveShadow = true;
    scene.add(sphere);
}

Although the code works offline, I'm having trouble running it in the browser. If you'd like to take a peek, here's the link to the fiddle containing the complete code: https://jsfiddle.net/redheadedmandy/f8fy4Lg8/1/

If any of you have any insights on how I could disrupt the uniformity of a three.js mesh, please do share your thoughts. All suggestions are greatly appreciated!

Answer №1

If you take a look at the jsfiddle demo, it's based on your initial example with some minor tweaks and updated to utilize the latest Three.js version.

For a more rugged appearance, you could approach it in this manner:

var shape = new THREE.SphereGeometry(70, 31, 17);

shape.vertices.forEach(v => {
  v.x += THREE.Math.randFloatSpread(2);
  v.y += THREE.Math.randFloatSpread(2);
  v.z += THREE.Math.randFloatSpread(2);
});

shape.computeFaceNormals(); // Important step when modifying vertices

There are countless techniques available for adjusting vertex coordinates within a geometry. Let your creativity guide you.

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

Utilizing jQuery to attach events to dynamically generated elements

I have a scenario where I am uploading multiple images and inserting them into specific div elements. These divs should toggle a class when clicked. Should I include the part of code that adds the onclick event inside the ajax success function? Your help i ...

Assign a variable the source of the web subsurface A-frame setting

I want to utilize the websurface A-frame component () to change the URL of the websurface when a button is clicked. I have defined a variable called source and I want the websurface URL to be updated to the value of this variable upon clicking the button. ...

Assigning a value to an input field using jQuery

I'm facing an issue while trying to set the value for an input using jQuery. Essentially, when you click on a link, it redirects you to a different page with a form, and I am attempting to set the value of one of the inputs in that form. Unfortunately ...

Exploring techniques to query a Mongoose/Express array generated from a select multiple option

I am currently working on a search form that utilizes the select multiple attribute. Below is the code snippet for the form. <form action="/search" method="get"> <select name="q" multiple> <optgroup label="Fruit"> <option ...

JavaScript queries in Selenium WebDriver

Lately, I have been using the selenium webdriver (nodejs module) along with mocha for writing automation tests, and encountered a few challenges along the way. Issue with Scrolling driver.findElement() seems to return false as it is unable to find the e ...

Extract objects from a nested array using a specific identifier

In order to obtain data from a nested array of objects using a specific ID, I am facing challenges. My goal is to retrieve this data so that I can utilize it in Angular Gridster 2. Although I have attempted using array.filter, I have struggled to achieve t ...

What is the process of embedding a Vue.js application into an already existing webpage using script tags?

My goal is to integrate a Vue.js application into an existing webpage using script tags. Upon running `npm run build` in my Vue application, I end up with 7 compiled files: app.js app.js.map manifest.js manifest.js.map vendor.js vendor.js.map app.css In ...

Error: Value of incoming scope in Angular Directive is not defined

When working in html, I passed an object into a directive like this: <lcd-code ldcCode="{{ detail.program.ldcCode }}"></lcd-code> The value of detail.program.ldcCode is "PSIH"... However, in the Directive, it is showing up as undefined: var ...

What is the best way to differentiate between a JSON object and a Waterline model instance?

Note: I have posted an issue regarding this on the Waterline repo, but unfortunately, I have not received a simpler solution than my current workaround. Within my User model, along with default attributes such as createdDate and modifiedDate, I also have ...

The scatterplot dots in d3 do not appear to be displaying

My experience with d3 is limited, and I mostly work with Javascript and jQuery sporadically. I am attempting to build a basic scatterplot with a slider in d3 using jQuery. The goal of the slider is to choose the dataset for plotting. I have a JSON object ...

Learn how to incorporate tooltips into Vuetify datatable headers for enhanced user experience

Previously, in older versions of Vuetify, it was possible to access the headerCell slot and easily add tooltips. You can refer to https://codepen.io/nueko/pen/dZoXeZ for more details. In the latest version, named slots are used, requiring knowledge of the ...

Reorder the Polymer dom-repeat element following a modification in the child component's value

My Polymer dom-repeat list is working fine on the initial value sorting for the children. However, when I update a value within a child element, the sort order of the list does not reflect the changes. What is the best way to achieve this? <body> ...

What is the process for sending body data through Swagger in a Node.js/Express environment?

Below is the configuration for my swagger: /** * @swagger * /api/addData: * post: * consumes: * - text/html * produces: * - text/html * parameters: * - name: author * in: body * required: true * ...

Setting up grunt-contrib-nodeunit to generate JUnit XML output: a step-by-step guide

I have been searching for information on how to configure reporters in the grunt-contrib-nodeunit module, as I recently added this task to my Gruntfile.js. nodeunit: { all: ['nodeunit/**/*.test.js'], } Does anyone know how to instruct Grunt ...

When refreshed, CSS and JavaScript were not loaded

As a newcomer to AngularJs, I am facing an issue that has left me puzzled. I am attempting to create a single-page application using AngularJS + ExpressJS. Everything is functioning properly, but I am encountering a problem upon page refresh. For example, ...

Creating a unique Angular JS / Material / Datatables application - Proper script loading sequence required based on page context

My top two declarations placed above the closing body tag. When used in a material dropdown page, the current order of these scripts works fine. However, when I switch to my datatables page (which is a separate page), I need to swap the order of the two s ...

Implementing styles from a constant file in React Native: A simple guide

In my file register.js, I have a UI component. import CustomHeader from '../components/Header'; ... static navigationOptions = ({navigation, navigation: { state } }) => { return { title: '', headerSty ...

Error: Brackets missing in the argument list

app.get("/editMBTI", editMBTIFunc(req, res) { // ensuring MongoClient is accessible in all EJS Files // app.locals.MongoClient= MongoClient; MongoClient.connect(url, function (err, client) { assert.equal(null, err); console.log( ...

Steps for inserting a script tag in an Angular component

My Angular/Typescript website needs to integrate a third-party script that generates a table. However, I'm facing issues with rendering the table within the home.component.html file. I've managed to embed the script, but it doesn't seem to ...

Challenges with 'this' reference in a requireif causing Vuelidate complications

     Need help with vuejs component using vuelidate and validations:     validations: {      invoice: {          dueDate: {              required,          },          tax: {              require ...