Eliminate the width and height segmentation parameters in the PlaneGeometry of three.js

I need assistance with removing the parameters widthSegments and heightSegments.

When I modify this line of code:

var tergeo= new THREE.PlaneGeometry(100, 100, 1, 1);

to:

var tergeo= new THREE.PlaneGeometry(100, 100, 0, 0);

The changes do not produce the desired result.

What is the correct approach to eliminate widthSegments and heightSegments in the following jsFiddle ?

Answer №1

Check out this alternative using an indexed buffer geometry:

body{
  overflow: hidden;
  margin: 0;
}
<script type="module>
import * as THREE from "https://cdn.skypack.dev/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c28342e39391c6c726d6f6a726c">[email protected]</a>";

let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 1, 1000);
camera.position.set(0, 0, 10);
let renderer = new THREE.WebGLRenderer();
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);

let g = QuadGeometry(THREE.MathUtils.randInt(5, 10), THREE.MathUtils.randInt(5, 10));
let m = new THREE.LineBasicMaterial({color: "yellow"});
let quad = new THREE.Line(g, m);
scene.add(quad);

function QuadGeometry(w, h){
  let pts = [
    [0.5, 0.5], 
    [-0.5, 0.5], 
    [-0.5, -0.5], 
    [0.5, -0.5]
  ].map(p => {return new THREE.Vector2(p[0], p[1])});
  let g = new THREE.BufferGeometry().setFromPoints(pts);
  g.setIndex([0, 1, 2, 3, 0]);
  g.scale(w, h, 1);
  
  return g;
}

renderer.setAnimationLoop(() => {
  renderer.render(scene, camera);
});
</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

What is the best way to retrieve an object's description from the Python Django backend and display it in the front end

When working with models, I have defined the object description as follows: def __unicode__(self): ............................... I want to display this description in my dynamic drop-down boxes that are generated using Ajax. However, all I see in the d ...

AngularJS is not responding to a 400 bad request

Despite my efforts to find solutions on Google and Stack Overflow for similar or identical issues, as a newcomer, none of them have provided me with any insight on how to resolve the issues in my code. Here is the script I am working with: $http.post(&ap ...

Trouble encountered with attributes object in RawShaderMaterial

I am struggling to generate my own content with threejs' RawShaderMaterial class. Here is what I have so far: var geometry = new THREE.RingGeometry(/* params */); //geometry.vertices.length = 441; var vertexFooAttribs = [/* 441 instances of THREE.Vec ...

How can Vue JS 3 components exchange data between each other?

I am attempting to share data from a variable favorite_count in the Favorites component located in the file Favorites.vue. My goal is to pass this data to the App Component in the App.vue file but I have been unsuccessful so far. I want any changes made to ...

Masking the identity of Google Pagespeed

Just starting to learn the ropes of javascript. How can I make Google Pagespeed anonymous? Check out the original code here: http://pastebin.com/xRbTekDA. It's functioning properly when I visit the page. Here is the anonymized version: http://pasteb ...

Tips on recycling JavaScript files for a node.js API

I'm currently using a collection of JS files for a node.js server-side API. Here are the files: CommonHandler.js Lib1.js Lib2.js Lib3.js Now, I want to reuse these JS files within an ASP.NET application. What's the best way to bundle these f ...

Error found when combining a stopwatch with the react useState hook and setInterval, causing an additional interval to start when the stopwatch

I have implemented a stopwatch feature that includes start and pause buttons. The start button triggers setInterval while the pause button calls clearInterval. Initially, pressing start and then pause works correctly. However, if you press start again afte ...

What is causing me to receive a Request Method of "GET" instead of "POST"?

I recently implemented the dropzone js library for uploading images and have a query regarding it. Is the POST method more suitable than GET when uploading an image? If yes, how can I rectify this? $(document).ready(function() { var myDropzone = new Dr ...

Using Knex in ExpressJS to insert a list of entries into SQLite with unique field constraints

I'm currently facing an issue with inserting a list of exercises into an sqlite database. The app is built on express JS and I am utilizing sqlite3 and knex to handle interactions with the DB. My goal is to add a set of exercises into the table exerci ...

Using a texture the same size as the original image in three.js / react-three-fiber: A step-by-step guide

I am facing a challenge in a project where I need to create a box to improve processing efficiency. The desired texture size is 16 px by 16 px. However, when I apply the texture to the box, it appears blurry regardless of the box size, as shown in the imag ...

Issue with Angular ngFor not updating radio button value when ngModel is set

Hello, I am fairly new to working with Angular and could really use some assistance with a problem I've run into. Essentially, I am receiving an array of objects from an API like this: [{name: "abc", score: 2},{name: ""def, score: ...

Convert a nested array of objects to an array containing only objects

I have a unique challenge with an array of nested objects. How can I create a new array of objects by extracting values from nested properties? In cases where the onClick property is empty, I need to look for a children property and exclude the parent elem ...

Guide on implementing automatic callbacks with AJAX

I am facing an issue with my index page that has one input tag and one division. There is an ajax function that retrieves data from the server, but I am encountering a problem. When I enter a single letter, it returns 3 records. Then, if I add another lett ...

Is there a way to assign a sessionStorage key by clicking on certain elements in HTML?

I have encountered an issue while attempting to set a value in the sessionStorage. The problem lies in storing the sessionStorage "key" differently based on the item clicked. For instance, if I click on the first view chat, I should store a key of "1", and ...

Triggering a link without navigating to it

Is there a way to open an API without revealing the link to users using JQuery or JavaScript? I typically use windows.open(...) for this purpose. ...

Resolve the issue of autofill data overlapping with field labels

My form incorporates the Canada Post AddressComplete tool, which functions similarly to Google Maps Autocomplete. As you type your address, suggestions appear in a drop-down menu. However, after selecting an address, the text in the Postal Code and City f ...

Order of execution behavior

I am currently working on a function that, when triggered, will populate the webpage with dynamic tiles. These tiles retrieve data from a remote database through an AJAX request and utilize jQuery 3.0 in the implementation. Function Implementation: funct ...

What is a way to transfer an Object from one Vue.js component to another without relying on vuex?

Using vue-router in app.vue, I defined the two components as shown below: <div class='app'> <div class='nav'> <router-link to='/a'>to A component</router-link> <router-link to= ...

Tips for ensuring that divs resize to match the container while preserving their original proportions:

#container { height: 500px; width: 500px; background-color: blue; } #container>div { background-color: rgb(36, 209, 13); height: 100px; } #one { width: 1000px; } #two { width: 800px; } <div id="container"> <div id="one">&l ...

to streamline the process of navigating Google Chrome web pages

Is it possible to create automation in Google Chrome that can complete the following tasks: 1. Input a job name to monitor 2. Periodically click a refresh button on the webpage (not the refresh button for the entire Chrome page in the left corner) 3. Open ...