How to properly align slices in volume rendering using THREE.js?

I have managed to create a stack of volumes from planes using THREE.js, but the planes disappear when they become orthogonal to the viewing plane (which makes sense). How can I prevent this from happening? Is there a way to keep the slices aligned with the view? Check out the JSFiddle example here

function init() {
  scene = new THREE.Scene();

  camera = new THREE.PerspectiveCamera( 45, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 1000 );
  camera.position.x = 0;
  camera.position.y = 20;
  camera.position.z = 1000;
  //camera.rotation.x = 45 * (Math.PI / 180);
  scene.add( camera );

  geometry = new THREE.PlaneGeometry(640, 352);

  for ( var i = 34; i <= 511; i ++ ) {
    var texture = THREE.ImageUtils.loadTexture( 'bodyslice/' + i + '.jpg' );
    console.info(texture);
    texture.magFilter = THREE.NearestFilter;
    texture.minFilter = THREE.NearestFilter;

    var material = new THREE.MeshBasicMaterial( { map: texture, opacity: 0.05,             transparent: true, depthTest: false} );
    var plane = new THREE.Mesh(geometry, material);

    plane.position.y = 300 - i;
    plane.rotation.x = 90 * Math.PI / 180;
    plane.doubleSided = true;

    scene.add( plane );
  }

  renderer = new THREE.WebGLRenderer({ antialias: false });
  renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  container.appendChild(renderer.domElement);
}

Answer №1

If my understanding is correct, simply shifting the slices around won't work because there would be empty space in between them that needs to be filled with new texture data. Rotating the planes could also disrupt the 3D image created by the slice textures.

An alternative solution might involve using slices/textures/planes in three dimensions (horizontal, vertical, and depth slices) to create a more cohesive volume representation. By viewing the volume from a direction perpendicular to one set of slices, you would encounter another set of planes. It's a bit difficult to explain, but if you envision your code in 2D, imagine the planes as parallel lines on a grid.

Another approach could be to extract individual pixels from the texture data and render them in 3D as cubes, planes facing the camera, or perhaps most efficiently as particles. Each particle would correspond to a pixel and display the color from the respective texture slice.

Answer №3

Utilize the lookAt() function available to all object3d instances to align the slices as a single object with this line of code:

volume.lookAt(camera.position);

Assuming that the names of the slices and camera are volume and camera respectively.

Keep in mind that it's crucial to group all the slices together for optimal results.

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

Struggling to extract information from a serialized Python object using JavaScript/jQuery?

Continuing the previous issue with an AJAX call to a Django view (restframework endpoint), the problem has now shifted to the frontend. $.ajax({ url: '/notify/', type:'GET', dataType: '', success: function (da ...

A guide to utilizing asynchandler within a class in Node.js

I'm currently in the process of converting my routers into a class structure, but I'm facing a challenge when trying to wrap the asyncHandler function inside the class. Can anyone provide guidance on how to achieve this? userController.js const ...

Can the MemoryRouter be successfully nested within the BrowserRouter in a React application?

I've been on a quest for some time now, trying to uncover whether it's feasible to utilize MemoryRouter solely for specific routes while maintaining the use of BrowserRouter in general. My goal is to navigate to a particular component without alt ...

JavaScript: Implementing a for loop to dynamically adjust CSS properties

How can I adjust the margin-top property of the ball element when clicking a button? Below is my current code, but it's not working as expected. Can you help? let ballMargin = ball.style.marginTop; moveButton.addEventListener('click', funct ...

Ways to retrieve a specific object property from an array of objects within a click event listener?

I have instantiated multiple object constructors and stored them in an array which I loop over to display as a list. Now, I am trying to extract the name property from that list to use in an onclick event handler (not included in this code). I am unsure of ...

Guide on how to reset a counter to 0 using a JavaScript button

I currently have a JavaScript counter and a button that increments the counter by 1. Here is my existing code: var counter = 0; var a = 0; var add = function(valueToAdd){ a += valueToAdd; document.getElementById('Value&ap ...

Tips for displaying a specific PDF file using the selected programming language

As a newcomer to react.js, I have a question regarding my system which allows the user to select the default language. If the chosen language is French, there is a specific URL that needs to be included in the Iframe path. For Spanish, it's a specific ...

Why aren't the vertices being updated once they are attached to a group?

My goal is to generate a group of lines starting with the following code: var geometry = new THREE.Geometry(); itemLine = new THREE.Line( geometry, material ); The current state of the geometry is as follows: geometry.vertices[0] Object { x: -540, y: ...

Execute the SQL "function" (or stored procedure?) whenever a database column is queried

Running on MySQL 5.6, I encounter a situation where various "name" columns in the database lack formatting and sanitization upon importation through CSV data dumps by customers each year. This results in names such as Phil Eaton, PHIL EATON, Phil EATON bei ...

Steps to show a particular row in a Vue.js API

I have a question about how to retrieve data from an API and display it in a textbox when the edit button on a specific row table is clicked. The data should include its own id along with other details. I apologize for sharing my code in this format, as I ...

What is causing the recursion function to return "NaN" in this scenario?

I'm trying to calculate the total sum of absolute differences between consecutive elements in an array using a function called sumAbsArr, but it seems to be returning NaN. var arr = [1, 5, 2]; var n = 3; var cur = 0; console.log(sumAbsArr(arr, n, ...

Tips for passing input fields from a React Function component to a function

How can I retrieve the values from 4 input fields in my react functional component using a function called contactMeButtonPressed? The inputs include name, email, company name, and message when the contact me button is clicked. Do I need to implement stat ...

Surprising mesh outcomes arising from the ThreeCSG boolean operation

I have a scene where I've implemented a boolean function to create holes in my wall. However, the lighting is exposing some issues with the geometry, as the shapes appear fragmented and the lighting looks incorrect. I want the surface to appear seamle ...

The REST request is preventing the JavaScript on the page from executing

Utilizing REST to POST data through Firefox's Poster tool and encountering a url: http://[ip]/page.jsp?paramater1=whatever&parameter2=whatever (Content Type: application/x-www-form-urlencoded) The page.jsp includes: <body onload="onload()"&g ...

What is the reason behind TypeScript's decision not to raise an error in case of a mismatched function argument type?

Here's a simple illustration to showcase my point: type Info = { id: number; } type ImportantInfo = { id: number; value: 5; } type Task = (data: Info) => void; const task: Task = data => null; const data: ImportantInfo = { i ...

Having difficulty in choosing the desired option from the dropdown menu

I seem to be facing a challenge with a dropdown list while trying to select the birth month. Despite my experience working on other websites, I have been unable to resolve this issue. I have attempted: Clicking using different locators. Using Action cla ...

Positioning of the dropdown in Material UI AutoComplete menus

Is there a way to turn off autocomplete auto position? I would like the autocomplete options to always appear at the bottom. Check out this link for more information! ...

Unleashing the Power of JavaScript: Converting Objects into

I need help converting JavaScript objects, specifically in a React project where I'm not very familiar with the language. Here is an object that I get back from an API call: { "api": { "results": 380, "fixt ...

How can you loop through keys and values in a JSON object using JavaScript?

I am attempting to cycle through the JSON data below: { "VERSION" : "2006-10-27.a", "JOBNAME" : "EXEC_", "JOBHOST" : "Test", "LSFQUEUE" : "45", "LSFLIMIT" : "2006-10-27", "NEWUSER" : "3", "NEWGROUP" : "2", "NEWMODUS" : "640" } The keys in this JSON are d ...

Issues with Javascript Date Function malfunctioning

I'm having trouble getting the text 'Oct 09, 2012' to display properly. Instead of running the function correctly, a bunch of unnecessary date text is showing up. Can anyone figure out what I'm doing wrong? Feel free to experiment with ...