Manipulate the curvature of a spline using three.js

In my current scene, I have a camera following a spline path.

This spline is generated using the CatmullRomCurve3() method in three.js.

However, there are bumps appearing automatically before and after the curve descends.

I am looking to eliminate these bumps so that the spline follows a smooth descent without any disruptions (while still maintaining the curvature).

I have experimented with different curve types like centripetal, chordal, and catmullrom, but the bumps persist.

If anyone has suggestions on how to achieve this, I would greatly appreciate it! Thank you

var renderer, scene, camera, spline;

renderer = new THREE.WebGLRenderer();
scene = new THREE.Scene();

renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, .1, 2000 );
      
camera.position.set(0, 0, 40);
camera.lookAt(0,0, 0);

spline = new THREE.CatmullRomCurve3([
  new THREE.Vector3( -70, 9 ),
  new THREE.Vector3( -12, 9 ),
  new THREE.Vector3( -8, 9 ),
  new THREE.Vector3( 8, -9 ),
  new THREE.Vector3( 12, -9 ),
  new THREE.Vector3( 70, -9 ),
]);


var points = spline.getPoints(500);

var geometry = new THREE.BufferGeometry().setFromPoints( points );

var material = new THREE.LineBasicMaterial( { color : 0xffffff } );

// Create the final object to add to the scene
var splineObject = new THREE.Line( geometry, material );

scene.add(splineObject);
renderer.render(scene, camera);
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>

Answer №1

If you're seeking a linear interpolation between points, using an instance of THREE.CatmullRomCurve3 may not be the right choice. Consider utilizing THREE.Path instead and connecting your points with .lineTo().

var renderer, scene, camera, spline;

renderer = new THREE.WebGLRenderer();
scene = new THREE.Scene();

renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 2000 );
  
camera.position.set(0, 0, 40);

var path = new THREE.Path();
path.moveTo( -70, 9 );
path.lineTo( -8, 9 );
path.lineTo( 8, - 9 );
path.lineTo( 70, -9 );

var points = path.getPoints(500);

var geometry = new THREE.BufferGeometry().setFromPoints( points );

var material = new THREE.LineBasicMaterial( { color : 0xffffff } );

// Create the final object to add to the scene
var splineObject = new THREE.Line( geometry, material );

scene.add(splineObject);
renderer.render(scene, camera);
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.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

Modify the text of a button in Angular to be underlined after it has

Is it possible to avoid DOM manipulation in the controller and keep it focused on business logic? I have a scenario with three buttons where I want to underline the text of the button when clicked. Here is a link to a demo: jsfiddle CSS: .underline { te ...

Include a serial number column when exporting a datatable to a PDF file

Currently, I am in the process of developing an e-commerce project using HTML and Javascript. One important aspect of my project involves displaying the details of ordered products. To achieve this, I have implemented Jquery Datatable to showcase the neces ...

problem arising from the origin preventing me from utilizing localStorage in conjunction with JSDOM

Currently, I am facing an issue while trying to load a webpage in a node environment using JSDOM. The webpage relies on localStorage for its functionality. I have attempted to load the webpage by utilizing JSDOM's URL configuration option and accessi ...

Can you provide instructions on how to display data in two lines within a mat-select field?

Is it possible to show selected options in mat-select with long strings in two lines within the same dropdown? Currently, the string appears incomplete. You can see an example of this issue here: incomplete string example <mat-form-field class="f ...

Looping through the ajax data to populate ion-item elements

I am currently working on a loop that retrieves user IDs, names, etc. from a JSON file. I am trying to display this data in a list view within an Ionic framework. When I simply use direct alerts in JavaScript, the users are displayed correctly, but when I ...

What is the best way to validate a nested object within an array?

Below is the schema I am working with: detail: [{ quantity: Number, product:{ name: String, code: Number, price: Number }, subtotal: Number ]} Here is the method I am u ...

Angular factory encounters 405 error with API $http delete request

In my factory, everything was running smoothly with regular ajax syntax from the controller. function endAgentSession(sessionData, tokenData) { var sessionId = sessionData.data.sessionId, access_token = tokenData.access_token, ...

What are some strategies for handling analytics tracking in Flux architecture?

Imagine I'm working on a cutting-edge single page application similar to Airbnb. One essential aspect of such an application is keeping track of when someone signs up for an account. There are numerous services available to assist with tracking, incl ...

Ways to delete a CSS attribute with jquery

Is there a way to eliminate a CSS property from a class without setting it to null? Let's say I have a class called myclass with the property right:0px. I want to completely remove right:0px from my class, not just set it to null. How can I achieve th ...

Issue encountered while trying to retrieve element within unnamed function in ajax system

Is there a way to fetch data from a file using Ajax when mousing over an element? My code seems to be working fine, but I'm having trouble accessing a <p> element inside an anonymous function. It seems like the element loses scope within the fun ...

Preventing opening while closed through the OnClick event

I have the following OnClick function: const [open, setOpen] = useState(true); and onClick={() => setOpen(!open != true)} The goal is to "close when open" and "remain closed if already closed". The current code achieves the second part but not the fir ...

Is it possible to automatically format a date as mm/dd/yyyy when typing into a date picker textfield in Nuxt.js?

In my Nuxt.js with Vuetify app, I successfully implemented a date picker that works well when selecting dates from the calendar. Now, I want to extend this functionality to allow users to type in dates as well. For example, if someone types "12122021", it ...

Cross-origin resource sharing (CORS) will still be ineffective, even when the Access-Control-Allow-Origin

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis est eu arcu tincidunt pulvinar. Aenean vel sapien vitae quam varius vulputate. Vestibulum et lacinia sem. Vivamus tristique mi ac metus tincidunt eget. // Donec fermentum al ...

Issue with disabled dates not refreshing in the view after adding them via button click

I have been utilizing the vue-hotel-date-picker plugin and it's been functioning well. The problem arises when I use the disabled dates props; it disables the dates initially when initializing and updating on the calendar. However, when I update the d ...

Troubleshooting issue: Chrome bug causing JavaScript full height intro section to have incorrect padding and display issues

Trying to create a full-height intro section using basic JavaScript markup has been quite the challenge. Here's a more detailed explanation: I have a parent DIV element that is supposed to adjust to the full height of the viewport. Unfortunately, t ...

Countdown timer that counts down in reverse when the browser is minimized

I am currently working on a JavaScript project where I have implemented a countdown timer in seconds. Once the timer hits zero, it triggers a specific function. The timer functions correctly, however, if the browser enters sleep mode or is minimized, the ...

"What is the best way to connect a md-input to the value of a md-slider

I'm in the process of developing an application using Angular 2.0/meteor, and I'm facing a challenge with binding an input to md-slider. Below is the HTML code for the component: <div class="panel-body"> <form [formGroup]="filtreFor ...

Tips for efficiently loading data into a vuex module only when it is required and addressing issues with async/await functionality

Is there a method to load all the data for a Vuex store once and only load it when necessary? I believe there is, but I am having trouble implementing it. I'm not sure if it's due to my misunderstanding of Vuex or Async/Await in Javascript promi ...

The request for JSON parsing encountered a failed attempt, resulting in an error while trying to parse the JSON

var userData = { "emailAddress": document.getElementById('emailAddress').value, "password": document.getElementById('password').value } var userDataString = JSON.stringify(userData); alert(userDataString); var url = "url"; var ...

What is the correct way to invoke a function within jQuery?

There must be a straightforward solution to what appears to be a simple and regular task. Inside the $(document).ready() function, I aim to invoke a function with a jQuery object - specifically without attaching it to an asynchronous event like mouseover ...