order in which child objects are drawn

Encountering the following issue:

I am attempting to create rings around Saturn, but they appear to be rendered in an incorrect order:

https://i.sstatic.net/rVg3H.jpg

The problem lies in how each planet is constructed. Each planet is a child of a different root object (THREE.Object3d), which contains a bodyContainer (THREE.Object3d). The BodyContainer holds the planet mesh. When I add the rings mesh to the body or bodycontainer, it appears as shown in the image above.

As a test, I created a 'free' sphere and rings, then added them directly to the scene where everything functioned correctly for objects added right to the scene.

Even if I attach the rings as a child of the sphere added to the scene, it works fine.

Below is the code I use to generate the planet body:

export default function generateBody(radius, basic, name) {


  var geometry = new THREE.SphereGeometry( radius, 24, 24 );
  var material;
  if(basic) {
      material = new THREE.MeshBasicMaterial({color: 0xFBE200});
  } else {
      material = new THREE.MeshLambertMaterial({
        //depthWrite: false,
        //depthTest: true,
      });

        if(textures[name].hasOwnProperty('map')) material.map = THREE.ImageUtils.loadTexture(textures[name].map);
        if(textures[name].hasOwnProperty('bump')) material.bumpMap = THREE.ImageUtils.loadTexture(textures[name].bump);
        if(textures[name].hasOwnProperty('specular')) material.specularMap = THREE.ImageUtils.loadTexture(textures[name].specular);
        if(textures[name].hasOwnProperty('normal')) material.normalMap = THREE.ImageUtils.loadTexture(textures[name].specular);
  }

  var mesh = new THREE.Mesh( geometry, material )
  mesh.scale.set( params.bodyScale, params.bodyScale, params.bodyScale );
  mesh.rotateX(Math.PI / 2);
  mesh.renderOrder = 0;

  return mesh;
}

and how i incorporate the rings:

  var circlemesh = new THREE.XRingGeometry(1.2 * (def && def.diameter || 139822000) * M_TO_AU / 2, 2 * (def && def.diameter || 139822000) * M_TO_AU / 2, 2 * 64, 5, 0, Math.PI * 2);
  var circleMaterial = new THREE.MeshLambertMaterial( {
    map: THREE.ImageUtils.loadTexture('../img/planet-textures/saturn/saturnringcolor.jpg'),
    alphaMap: THREE.ImageUtils.loadTexture('../img/planet-textures/saturn/saturnringpattern.gif'),
    //transparent: true,
    side: THREE.DoubleSide,
    //depthWrite: false,
    //depthTest: true
  });
  var mesh = new THREE.Mesh(circlemesh, circleMaterial);
  mesh.renderOrder = 1;
  this.body.add(mesh);

furtheron:

this.bodyContainer.add(this.body)
this.root.add(this.bodyContainer)
scene.add(this.root)

For testing on a sphere attached directly to the scene, I used a simple sphere geometry and the same mesh for rings as utilized here.

        var circlemesh = new THREE.XRingGeometry(1.2 * 5, 2 * 5, 2 * 64, 5, 0, Math.PI * 2);
      var circleMaterial = new THREE.MeshLambertMaterial( {
        map: THREE.ImageUtils.loadTexture('../img/planet-textures/saturn/saturnringcolor.jpg'),
        alphaMap: THREE.ImageUtils.loadTexture('../img/planet-textures/saturn/saturnringpattern.gif'),
        transparent: true,
        side: THREE.DoubleSide,
        //depthWrite: false,
        //depthTest: true
      });
      var ringmesh = new THREE.Mesh(circlemesh, circleMaterial);
      //ringmesh.renderOrder = 1;
      //scene.add(ringmesh);

var SPHEREgeometry = new THREE.SphereGeometry( 5, 32, 32 );
var SPHEREmaterial = new THREE.MeshLambertMaterial( {color: 0xffff00} );
var sphere = new THREE.Mesh( SPHEREgeometry, SPHEREmaterial );
//sphere.renderOrder = 0;
scene.add( sphere );

sphere.add( ringmesh );

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

Answer №1

The issue was resolved by adjusting the proximity of the camera. No additional material parameters were required.

Answer №2

If you're looking to implement Object3D in a hierarchy with parent and child relationships in THREE.js, here's how you can do it:

Check out this Object3D Parent Child Fiddle

const parent = new THREE.Object3D();
const childContainer = new THREE.Object3D();
parent.parent = childContainer;
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const mesh = new THREE.Mesh(geometry, material);
parent.add(mesh);
childContainer.add(parent);
scene.add(childContainer);

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

Can you assist with transforming the html, css, and js code into a svelte format using style lang="postcss" specifically for tailwind?

I'm attempting to transform this shining button from a codepen I discovered into a svelte component, but for some reason the sparkles don't appear. I'm unsure if it's relevant, but I'm also utilizing Tailwind CSS, so my style tag h ...

Push-grid interaction through drag-and-drop feature

I'm on a quest to incorporate grid drag-and-drop functionality into my project. While there are numerous frameworks available that offer this feature, one of the most popular options is JQuery UI's sortable library. However, I am specifically lo ...

Unable to view Bootstrap Icons in Gulp 4

I recently integrated the new bootstrap icons npm package into my project using Gulp 4, the latest version. Everything was installed successfully and was working smoothly. However, I encountered an issue when trying to declare the icon in my index.html fi ...

Attempting to extract the cell information and choose an option from a cell using the Tabulator program

I've been using Tabulator, which is an amazing tool, but I've run into a little trouble. I'm trying to add an HTML Select in each row, with options specific to each record. When I change the select option, I call a function and successfully ...

Can you choose and generate identical values using react-select?

I am working on implementing a multi Creatable feature where users can select a preset value or create a new value during the same interaction. To illustrate, here is my current render: import CreatableSelect from 'react-select/creatable'; functi ...

access the content of a div element by its class attribute

Within the div element, a value has been set and I am attempting to retrieve this value using its class. However, the code below does not return the desired value. What mistake am I making here? How can I resolve this issue? <div title="Find on Amazo ...

Utilizing the power of Vue Router with DataTables

I am currently facing an issue where I want to include links or buttons in my DataTable rows that can navigate to a vue route when clicked. The straightforward approach would be to add a normal <a> element with the href attribute set to "/item/$ ...

Creating a Stroke on an html5 canvas with the help of EaselJS

As a newcomer to Easel and HTML5, I am attempting to draw a line on a canvas using EaselJS. The X-coordinate is set to 100 while the Y-coordinate is taken from an array list. Below is the code I have written. Can someone please help me identify where my ...

Alignment issue with Bootstrap 4 form fields within inline form group

My experience with Bootstrap 4 on certain pages has been quite challenging, specifically when it comes to aligning fields with labels to the left and maintaining an aligned appearance for input fields. Here is the snippet of my code: <div class="wrap ...

What is the best way to implement a scrollbar in a specific div rather than the entire window?

Hey everyone! So, I have this window in electronJS with a div where I'm dynamically adding elements using Javascript and the function --> document.createElement('section'). Here's the loop in Javascript to add these elements: for ( ...

How to Handle 404 Errors for Specific Express Routes and Not Others

Struggling with the setup of a single page app using Angular routes on the front end, while facing backend issues. All database-related routes are functional, but any additional route designed to serve an HTML file or simple text like "hello world" result ...

I am experiencing an issue where the result is not appearing on the input tag within my

<script> <form action="do-add-cek.php" id="myForm" method="post" enctype="multipart/form-data"> <div class="form-group"> <label> ...

Invoking Node to utilize React/Webpack module code

Trying to figure out how to integrate client-side import/export modules into a Node.js require script within my custom NextJS webpack config: module.exports = { webpack: (config, options) => { if (options.isServer) { require("./some-scr ...

Tips for generating JavaScript within list elements using a PHP script

My PHP script is designed to fetch data from a database and display it as list items within a jQuery Dialog. The process involves creating an array in the PHP while loop that handles the query results, with each list item containing data, an HTML button, a ...

Ways to Prevent Accidental Double Clicking of an Ajax Button

Struggling to input data into the database through an AJAX call. My issue arises when I inadvertently click the button twice, resulting in duplicate data entries. This problem has been troubling me. How can I prevent this from happening? <from>& ...

Creating a custom decision tree in Angular/JS/TypeScript: A step-by-step guide

My current project involves designing a user interface that enables users to develop a decision tree through drag-and-drop functionality. I am considering utilizing GoJS, as showcased in this sample: GoJS IVR Tree. However, I am facing challenges in figuri ...

What is the best way to prevent a draggable div from moving past the edge of the viewport?

My situation involves a draggable div that functions as a popup window when a specific button is clicked. However, I noticed that dragging the div to the end of the viewport allows me to drag it out of the visible area, causing the body of the page to expa ...

Unsure how to proceed with resolving lint errors that are causing changes in the code

Updated. I made changes to the code but I am still encountering the following error: Error Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. It is recom ...

An AngularJS Dilemma: Troubleshooting JSON Integration

I am working with a JSON source and trying to fetch results from it using a post request. Interestingly, when I use the POSTMAN extension in Chrome, everything works perfectly fine. However, when I try the same thing with AngularJS, the page keeps loading ...

The reason for my inability to include a fresh method in String.prototype using typescript

I attempted to extend the String.prototype with a new method, but I encountered an issue. interface String { newMethod(): void } String.prototype.newMethod = function() {} Although there were no errors in the typescriptlang.org playground, I received ...