Is it possible to incorporate diagonal lines into a GridHelper object using Three.js?

I am really interested in achieving the effect seen in the first image below (I also want to replicate the opposite diagonal, but I can figure that out later). The second image shows a standard GridHelper.

https://i.sstatic.net/iIQZO.png

Do you think it would be feasible to create this effect by adding another grid helper and rotating it 45 degrees along the y-axis?

After searching through the official documentation, I couldn't find any information on how to do this. So I assume there might be an alternative method. Does anyone have any suggestions on how to achieve this?

This is the code I used for the GridHelper:

grid = new THREE.GridHelper(80, 15, 0x000000, 0x000000);
grid.position.y = -0.2;
scene.add(grid);

My intuition tells me that the solution might involve using EdgesGeometry. However, I'm not completely certain about the correct approach due to:

EdgesGeometry( geometry, thresholdAngle )

Where the geometry parameter needs to be a valid geometry object.

Is the GridHelper considered a geometry object? You can review the official documentation here.

EDIT: For reference, here is a visual example demonstrating my current situation: codepen example.

Answer №1

To achieve the desired result, use THREE.PlaneBufferGeometry() along with a material that has wireframe: true.

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 50, 25);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xffffff);
document.body.appendChild(renderer.domElement);

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

var gridGeometry = new THREE.PlaneBufferGeometry(80, 80, 15, 15);
gridGeometry.rotateY(Math.PI);
gridGeometry.rotateX(-Math.PI * .5);
var gridMaterial = new THREE.MeshBasicMaterial({
  color: "black",
  wireframe: true
});
var gridWithDiagonals = new THREE.Mesh(gridGeometry, gridMaterial);
scene.add(gridWithDiagonals);

render();

function render() {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}
body {
  overflow: hidden;
  margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/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

Implement a delay for a specific function and try again if the delay expires

In my TypeScript code, I am utilizing two fetch calls - one to retrieve an access token and the other to make the actual API call. I am looking to implement a 1-second timeout for the second API call. In the event of a timeout, a retry should be attempted ...

Angular data binding between an input element and a span element

What is the best way to connect input texts with the innerHTML of a span in Angular6? Typescript file ... finance_fullname: string; ... Template file <input type="text" id="finance_fullname" [(ngModel)]="finance_fullname"> <span class="fullnam ...

What are the steps to import a .obj 3D model into Three.js?

After incorporating your advice, here is the revised code: var renderer = new THREE.WebGLRenderer( { alpha: true } ); renderer.setSize( window.innerWidth, window.innerHeight ); element.appendChild( renderer.domElement ); var loader = new THREE.OBJLoader( ...

ES6: utilizing properties and methods of a subclass that inherit from the superclass

While ES6 does not have abstract methods or properties, is it possible to access some methods or properties from the parent class in an inherited class? class ParentClass { constructor(){ ParentClass.checkChildPropertyAccessibility(); Pa ...

Exploring the world of technology with jQuery, harnessing the power of JSON objects

I'm seeking assistance with creating JSON using JQuery, sending it via Ajax to a .NET webservice, and then deserializing it in .NET in order to save the data to a database. If anyone could provide guidance on where I might be going wrong, that would ...

Dynamically Exporting Node Modules

// custom-exports.js exports.createCustomExports = (exportObject) => { module.exports = exportObject for (const exportItem in exportObject) { exports[exportItem] = exportObject[exportItem] } } // calculations.js const { createCustomExports } = ...

The communication between the view and the model is failing in Angular JS, causing data not to be

I'm encountering an issue where the text field input in my view is not binding to the controller. Below is the snippet from the view: <md-dialog-content ng-if="mode=='addSentence'" class="sticky-container"> <md-input-container ...

What is the process for obtaining the cypress interception fixture twice but in two distinct formats?

Hi there, I'm new to Cypress and facing a challenge that I hope you can help me with. In my test file, I have the following code: cy.SetupClassificationsStubFixture(1); This code refers to a custom command that I've created: Cypress.Commands.ad ...

JavaScript: Creating an array to store the most recent 5 search queries

I am creating a React-Redux application with a search feature based on city names. https://i.sstatic.net/eFGVz.gif Below the input field, I want to display the last 5 cities that have been searched for. To achieve this, I am storing all entered cities i ...

Updating the attributes of an FBX object in ThreeJS post asynchronous loading

I have successfully loaded an FBX Object into the scene const objLoader = new FBXLoader(); objLoader.load( '{{asset('models/model.fbx')}}', function ( object ) { scene.add( object ); object.position.y = 0 ...

When the response is manually terminated, the next middleware layer in express.js is invoked

I recently noticed an unusual occurrence: Even though I am explicitly ending the request using res.json() in one express middleware, the request still cascades down to the next middleware. It is important to mention that I am not utilizing next() anywhere ...

Troubleshooting: Why is Jquery unable to retrieve image height?

Having trouble using jQuery to find the actual height of the first image nested within a container. I can access the src attribute but not the height. Any suggestions on how to get the accurate height? Is it necessary to retrieve heights via CSS? Unfortu ...

Immediately executing $digest following $watch's declaration results in an error message stating "$apply is currently in progress

I am new to Angular and I'm trying to figure out why I'm getting the error "$apply is already in progress..." with the following code snippet. Here is the code, which closely resembles what's in the Angular documentation: https://docs.angul ...

Sending a POST request to a PHP file in React: A Step-by-Step Guide

Just starting out with reactjs and trying to figure out how to send an ajax request to a server (php file). Here's the structure of my project: check it out here src/index.js import React from 'react'; import ReactDOM from 'react-dom& ...

How can I protect a text or script file from being accessed or downloaded by entering its URL directly into the browser address bar?

While working on my JSP file, I have incorporated some Java-script code but to safeguard it from being visible to clients, I decided to store it in a separate codescript.js file and load it using ajax like so: $.ajax({ cache: true, dataType: "script ...

what are some advanced techniques for manipulating the DOM with a datatable?

I am currently involved in a project where we are presenting the data summary for each year to the user. The summary includes the total data for each year (counted rows). View Data Summary: Click here When the user clicks on the "+" icon, they will be ab ...

Struggling with accurately configuring the input field in AngularJS?

Struggling with clearing the input field I have been attempting to clear the input box with ng-model="newInstruction.instructionText" after a new instruction text is added. However, the input field does not clear even after trying to reset it to an empty ...

Controlling dropdown menus filled with AJAX responseData

When it comes to Javascript, JQuery has always been a reliable companion for me. However, there are instances where I encounter challenges that require some extra effort to overcome. Today happens to be one of those days. I've stumbled upon an issue t ...

Turn a textfield on and off in real-time

Hey everyone, I've been working on making a textfield dynamic and I wanted to share my code with you: <input type="text" id="test1" value ="dynamic" onfocus="this.disabled=true" onblur="this.disabled=false"> <input type="text" id="test2 ...

Is it possible to refresh my application without using window.location.reload() or ngOnInit()?

Is it possible to refresh my Angular 11 app without using window.location.reload() or ngOnInit()? I've encountered issues with both methods - window.location.reload() reloads the tab in Chrome which is not ideal, and ngOnInit() causes strange bugs in ...