Sides of the BoxGeometry

I previously inquired about a particular issue on this post: Adding Thickness to Faces

The main problem has been resolved, but now I have encountered a new issue. Initially, my walls were set to side:THREE.BackSide so they didn't display when facing the camera. However, now that they have thickness, this setting no longer works and I'm unsure of the reason behind it.

Here is the image before: Before

And here is the image after: After

How can I make the thick walls act like the Plane walls did?

Answer №1

Here is a basic idea for controlling the visibility of a wall with some modifications:

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

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

scene.add(new THREE.GridHelper(10, 10));

var points = [
  new THREE.Vector3(-2, 0, 2),
  new THREE.Vector3(2, 0, 2),
  new THREE.Vector3(2, 0, -2),
  new THREE.Vector3(-2, 0, -2)
]

var walls = [];

points.forEach((p, idx, points) => {
  let nextIdx = idx === points.length - 1 ? 0 : idx + 1;
  buildWall(p, points[nextIdx], 2, 0.1);

});

function buildWall(pointStart, pointEnd, height, thickness) {

  var boxW = pointEnd.clone().sub(pointStart).length();
  var boxH = height;
  var boxD = thickness;

  var boxGeometry = new THREE.BoxGeometry(boxW, boxH, boxD);
  boxGeometry.translate(0, boxH * 0.5, 0);
  boxGeometry.rotateY(-Math.PI * 0.5);
  var wall = new THREE.Mesh(boxGeometry, new THREE.MeshBasicMaterial({
    color: "aqua",
    wireframe: true
  }));
  wall.position.copy(pointStart).add(pointEnd).multiplyScalar(0.5);
  wall.lookAt(pointEnd);
  scene.add(wall);
  walls.push(wall);
}

var currentPosition = new THREE.Vector3();
render();

function render() {
  requestAnimationFrame(render);
  walls.forEach(w => {
    w.visible = currentPosition.copy(w.position).sub(camera.position).lengthSq() > camera.position.lengthSq();
  })
  renderer.render(scene, camera);
}
body {
  overflow: hidden;
  margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/91/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

Jquery's remove function fails to function correctly when used on a cloned element

I am facing an issue where I have a list of rows that need to be deleted. However, when I attempted to use jQuery's remove function, it only removed the original row and not its clone. My goal is for the parent element of the parent to be removed when ...

Ways to extract innerHTML content from a loaded element generated by using the .load() method

Check out the code snippet below: template.html : <div id="nav"> Welcome to Space </div> layout.html : <div id="content"> </div> $('#content').load("template.html #nav"); ale ...

Divide a string into smaller sections beginning at " ] " and concluding with "As"

In Microsoft SQL Server 2008 R2, I have fetched a string from a stored procedure using the query: EXEC sp_helptext 'MyStoredProcedureName';. My task is to divide this string into arrays or substrings that start from the closing parenthesis "]" a ...

Responsive Alignment of Slanted Edges using CSS

I have been working on creating a responsive diagonal layout with slanted shapes (refer to the image attached). However, I'm facing a challenge with aligning the edges smoothly at different screen sizes, especially when the rows grow and the screen re ...

The tooltips in the WordPress-Gulp-Starter-Kit running on Bootstrap 5 do not seem to be functioning properly

I'm having trouble with tooltips not working properly. The codebase I'm using is from this repository https://github.com/oguilleux/webpack-gulp-wordpress-starter-theme If you need more details, feel free to reach out. Here is my main.js file: ...

Revamp the state within a React component

I created a component that organizes logos within a grid system. The component receives 2 props: grid (which contains the logos) and limit (indicating the number of logos to be displayed). type Props = { grid: [], limit: number, }; type Sta ...

Tips for extracting information from a Javascript Prompt Box and transferring it to a PHP variable for storage in an SQL database

My current issue involves a specific function I want my script to perform: before a user rejects an entry on the server side, the system needs to prompt a text box asking for the reason behind the rejection. The inputted reason should then be saved to a My ...

Executing a file upload using ng-click="upload('files')" within Selenium Webdriver

Is it possible to automate a file upload when the HTML code does not include an < input type='file' > instead, uses a link <a ng-click="upload('files')"> File Upload </a> Clicking this link opens a file selector f ...

The submit form and cordova functions are failing to trigger

I am encountering an issue where I cannot successfully call the submitForm() function when attempting to trigger it via ng-submit. The function does not execute as expected. How can I troubleshoot and resolve this problem? (function () { 'use str ...

Issues have been identified with the functionality of the Am charts v3 XY in conjunction with a

I'm currently working on a project with angularJS and utilizing the npm package amcharts3 "^3.21.15". I've encountered a minor issue regarding the logarithmic scale in my XY chart. Below is my chart without the logarithmic scale: View working ch ...

Why does the address bar show value changes in IE when using window.location.hash, but the value doesn't change in the DOM when going

Here is a sample JavaScript code that attempts to detect the back button event: document.location.hash="#1"; document.location.hash="#2"; document.location.hash="#3"; function check() { if("#3"!=window.location.hash) { alert("Back button clic ...

Develop an engaging billboard carousel using jQuery

After coming across a tutorial on tympanus, I decided to make some modifications to create a rotating billboard effect. However, something seems to be going wrong and it's driving me crazy trying to figure out the problem! $(function() { $('#ad_ ...

What strategies can be implemented to effectively utilize both client-side and server-side validation without redundant efforts?

Currently, I am validating user input on the server side using PHP. However, the client side sends XMLHttpRequest calls and highlights invalid fields with red borders. While this method works well, I believe it can be time-consuming for users to wait for a ...

Having issues updating cookies with jQuery in ASP.NET framework

On my asp.net web page, I have implemented a search filter functionality using cookies. The filter consists of a checkbox list populated with various categories such as sports, music, and food. Using a jQuery onchange event, I capture the index and categor ...

Cloning jQuery with varied PHP array value

So, I have the given PHP values: PHP: <?php $names = array("Mike","Sean","Steve"); ?> <script type="text/javascript"> var name_data = <?php echo json_encode($names); ?>; </script> <div class="container"> <div cl ...

Configuring Angular to use ES6 syntax

Trying to integrate angular google maps with es6 syntax has been a challenge for me. In es5, the code typically looks like this: .config(function(uiGmapGoogleMapApiProvider) { uiGmapGoogleMapApiProvider.configure({ // key: 'your api key&ap ...

What is the best way to create a function that requires an argument in TypeScript?

I'm looking to bring in a module that requires an argument in Typescript. This is how it looks in javascript: const cors = require('cors')({origin: true}); // JS What would be the equivalent syntax in Typescript? ...

Is there a way to determine the top center of a rotated Cylinder in THREE.js?

Just starting out with WebGL and Three.js, I managed to create a cylinder with the original point at the bottom center. Here's the code snippet: var cylinderGeometry = new THREE.CylinderGeometry( topRadius, botRadius, randomCyliderHeight); cylinderG ...

Optimizing 3D rendering efficiency and pipeline for level of detail (LOD) meshes using three.js

Seeking advice after a long time away from working with 3D models, as the landscape has significantly evolved since then. I have highly detailed 3D models (each with over 3 million faces) created from real-world terrain scans that I need to render in a we ...

Preventing the window from resizing while an AJAX query is in progress

I have a script in jQuery that serves as a search tool and also has the capability to resize an element to match the screen height minus 40 pixels whenever the window is resized. However, I am looking for a way to turn off the resizing feature when a searc ...