What is the correct method to display a THREE.Line in the correct sequence?

Currently, I am in the process of constructing a model solar system and have been using THREE.Line to create orbits for my planets. Everything seems to be going well until you view the orbits from the front of a planet, revealing that they are actually being rendered behind the Meshes. Despite adjusting render order and depthwrite, I have not been able to achieve the desired effect where the orbit wraps around the planet. This should be a simple task in theory. In case you're wondering, the effect I am aiming for can be seen here: what i'm looking for, with a single orbit fully encircling the planet. The issue is illustrated by this image of what my problem looks like: [what i have][2].

Below is the function responsible for creating the orbits:

function MakeOrbit_2(base, color) {
    function semiminor(a, e) {
        return a * Math.sqrt(1 - (e * e));
    }
    var curve = new THREE.EllipseCurve(
        foci(1000 * base[9], semiminor(1000 * base[9], base[0])), 0,            // middle point
        1000 * base[9], semiminor(1000 * base[9], base[0]),           // xRadius, yRadius
        0, 2 * Math.PI,  // startAngle, endAnge
        false,            // clockwise
        0                 // rotation
    );
    var material = color;
    var geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(points))
    var orbit = new THREE.Line(geometry, material);
    orbit.rotateX(- Math.PI / 2);
    orbit.rotateZ(DegToRad(base[3]));//ascn
    orbit.rotateX(DegToRad(base[2]));//inc
    orbit.rotateZ(Math.PI + DegToRad(base[4]));//aop
    scene.add(orbit);
    return orbit;
}

I have included renderer.sortObjects = false; to ensure proper rendering of transparent atmospheres and clouds. It's important to mention that less opaque lines behave differently compared to fully opaque ones. Update: The peculiar effect was attributed to rounding errors as the scale exceeded billions of units, resulting in minimal differences in position that did not significantly affect the z-buffer.

Answer №1

After stumbling upon a fascinating example created by Sander Blue, who also shared his GitHub source code, I was introduced to the world of 3D Javascript for the first time. It truly left me in awe! In addition, the mention of your name struck a chord with me - Logan from my mom's side and Brotherston from my dad's side. Quite a coincidence, isn't it? While I don't have a direct answer to your query, I believe these links may assist you. The example showcased aligns perfectly with what you were seeking: displaying orbits in front of a planet as you manipulate the view.

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

PugJS is failing to properly interpolate numbers from the JSON file

My goal is to display a list of interfaces retrieved from my router API, which is in JSON format. However, when using Pug, only the strings are being rendered and not the numbers. Here is the output (it displays correctly in HTML): em1 192.168.0.0/24 Addr ...

Synchronous loop in Javascript

Is there a method to execute codes asynchronously within a for loop? In this scenario, events ranging from day x to y need to be inserted into the calendar using a for loop. However, the current loop is taking too long, as it has to cover all the days fro ...

Looking to pull out the .js URL from a website?

Looking to extract a .js link from a webpage. How can I locate the JavaScript page link within the source code of a web page? I am specifically interested in a Java-based solution for this task. ...

Trigger an alert message upon loading the HTML page with search text

I need to search for specific text on a webpage and receive an alert if the text is found. <script type='text/javascript'> window.onload = function() { if ((document.documentElement.textContent || document.documentElement.innerText ...

What is the process for refreshing Textures in ThreeJs?

How can I refresh my skybox textures by selecting thumbnails? You can check out this example for reference: canvas_geometry_panorama.html Each thumbnail title corresponds to a folder that contains the skybox images. By using a simple jQuery script, a ...

Retrieve ALL information from a third-party API request with a limit of 1000 calls

Challenge: Implementation of a third-party API call using Node.JS. The API link restricts the number of users per call to 1000, with an option to retrieve the next set by passing parameters in the URL (?firstResult=1001&maxResults=1000&orderBy=NAME ...

Incorporating a classList.toggle into a snippet of code

button, p, h1, h2, h3, h4, h5, a{ /* Define specific elements to use "fantasy" font */ font-family: Tahoma; } #main_body{ margin: 0px auto; background-color: #dedede; } #top_body{ /* Remove margin for simplicity */ } #t ...

Error in Function Due to Undefined jQuery DataTable Parameters

In the jQuery datatable column, the below JavaScript code will display either a green checkmark button or a red X button: { data: "HasPayment", render: function (data, type, row, meta) { if (data) { return '<bu ...

A guide on breaking down a URL string containing parameters into an array with the help of JavaScript

I need help splitting a long string into an array with specific index structure like this: fname=bill&mname=&lname=jones&addr1=This%20House&... I am looking to have the array set up as shown below: myarray[0][0] = fname myarray[0][1] = b ...

What is the best way to locate this specific element?

<div class="ptp-item-container"> <div class="plan">New Text to Display!</div> <div class="price">200</div> <div class="bullet-item">some other text</div> <div class="cta"> <a class="button" ...

exploring the depths of nested objects and utilizing the 'for in

My issue involves receiving a json response from an API that includes objects within objects. It looks something like this: {Object}->{results}->{manyObjects} When I execute the following code: var list = data.results.list; for(val in list){ ...

Having trouble getting the jquery tabify plugin to work properly

I've put in a lot of effort and double-checked everything, but for some reason this tabify function just won't work. I have gone through my code 100 times but still can't seem to pinpoint the error. Here is the code I am working with: <! ...

I am unable to create a visual representation using the data obtained from the API

After utilizing Redux-Saga to fetch data from an API, I encountered difficulties accessing the updated state. This issue may stem from attempting to retrieve the data before it has been fully loaded into the redux state. //saga.js import axios from ' ...

The commencement of setTimeout relies on my decision to halt the page's operation

During a form submission, my jQuery AJAX function is used to query the amount of data uploaded from a file. This information is then utilized in creating a progress bar. Here is an example of my JavaScript file: var formSubmitted = ''; var count ...

Obtaining images from JSON data and displaying them in a modal using AngularJS

Utilizing AngularJS to retrieve a JSON file: { "albumId": 1, "id": 1, "title": "accusamus beatae ad facilis cum similique qui sunt", "url": "http://placehold.it/600/92c952", "thumbnailUrl": "http://placehold.it/150/92c952" }, and showcasing it with ...

Comparing Methods for Populating Dropdown Lists: JavaScript vs Database Integration (Mysql-Django)

I am looking to implement 3 dropdown lists that work together: Select: State Select City Select: Restaurant When a selection is made in the first dropdown list, it should update the "Select City" list. Similarly, when a selection is made in the sec ...

The functionality of Bootstrap's push and pull options appears to be malfunctioning

Exploring the grid option pull and push has presented some challenges for me. I suspect the issue lies in my implementation of bootstrap CSS and/or JS (not certain if push/pull are controlled by JS or CSS). I've included a push-pull setup at the top ...

Ending an $.ajax request when the page is exited

Currently, I have a function set on a timer to retrieve data in the background: (function fetchSubPage() { setTimeout(function() { if (count++ < pagelist.length) { loadSubPage(pagelist[count]); fetchSubPage(); ...

How can I assign a URL when a button is clicked in Next.js?

Can I manipulate queryString values using nextjs and reactjs? I have a filter list on my page that changes the displayed results when clicked. I want to update the URL's queryString values so that if a user navigates away from the page and then retu ...

"Unpredictable behavior observed with useSWR hook or potential issues with outdated closure function

Within my React functional component, I have implemented a Lesson Video Player that functions similarly to Instagram Stories. Each lesson contains videos ("clips") with interactive elements that trigger a multiple-choice quiz for the user. Below is a simpl ...