Using apply quaternion is not a valid function

Can anyone shed some light on this issue I'm having while attempting to set vertices of a geometry using a quaternion? The code snippet I've been using is:

geometry.attributes.position.array[x].applyQuaternion(quaternion)

However, it doesn't seem to be working as expected. I am aware that there have been changes in the implementation in the past and I suspect that the problem lies in the fact that

geometry.vertices[x]

is no longer accessible. Any insights on this?

Answer №1

The function .applyQuaternion() can only be used with a Vector3 object, not with a simple number. Trying to use 7.applyQuaternion() on a number is invalid because it doesn't make sense to apply a 3D rotation to a 1-dimensional value.

To solve this issue, ensure that you first create a Vector3 using the XYZ coordinates of the vertex you want to manipulate by utilizing the BufferAttribute.get... method:

// Create quaternion
const quat = new THREE.Quaternion();
quat.setFromAxisAngle( /* ... */ );

// Get position attribute
const posAttrib = geometry.getAttribute('position');

// Obtain the XYZ components of the 7th vertex in the geometry
const twistVec = new THREE.Vector3(
    posAttrib.getX(7),
    posAttrib.getY(7),
    posAttrib.getZ(7)
);

// Now that you have a Vec3, you are able to apply a quaternion
twistVec.applyQuaternion(quat);

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

Error 404 encountered when attempting to send a JSON object to the server

I've been facing a problem while trying to send a JSON object to the server using AJAX calls. I keep getting a 404 Bad Request error. The issue seems to be related to the fact that I have a form where I convert the form data into a JSON object, but th ...

Is there a way in Vue to switch between encrypted and unencrypted content in an input field?

I'm grappling with the challenge of creating an input field where the contents are initially hidden as 'ab****gh' and can be toggled to reveal as 'abcdefgh' upon a click. I've been experimenting with some code, but I'm st ...

How can I incorporate a JavaScript module into my Typescript code when importing from Typeings?

Exploring Angular2 and Typescript with the help of mgechev's angular2-seed for a new project has been an interesting experience. However, I have encountered a problem along the way. My intention is to incorporate Numeral into a component, and here ar ...

Is it possible to provide unrestricted support for an infinite number of parameters in the typing of the extend function from Lodash

I am utilizing the "extend" function from lodash to combine the objects in the arguments as follows: import { extend } from 'lodash'; const foo1 = { item: 1 }; const foo2 = { item: 1 }; const foo3 = { item: 1 }; const foo4 = { item: 1 }; const f ...

When the user clicks on the iframe, they will be redirected to the

My goal is to create a scenario where clicking on an iframe opens the same URL in a new browser tab, while ensuring that scroll and other mouse events within the iframe are not affected. I have experimented with various approaches but none have been succe ...

Ways to deactivate a button using CSS

I need to use Javascript to disable a link based on its id. By default, the link is invisible. I will only enable the link when the specific id value comes from the backend. HTML <li id="viewroleId" style="display: none;"> <a href="viewrole" ...

Having trouble retrieving the input value using JavaScript

I have been attempting to retrieve the value of an input tag using JavaScript and display it on the console, but my code seems to be not functioning properly. Can someone help me identify the issue in the following code snippet? const userTextValue = doc ...

What strategies can I implement to prevent duplicate entries while utilizing pagination with MongoDB?

I have been working on a blog web application where I aim to showcase posts on the main page. Currently, I am using MongoDB to fetch posts based on tags. My goal is to have the content on the home page appear random and diverse, incorporating both the lat ...

The md-select search filter currently functions according to the ng-value, but it is important for it to also

I am using a md select search filter with multiple options available. For instance: id: 133, label:'Route1' id: 144, label:'Route2' id: 155, label:'Route3' id: 166, label:'Route4' If I input '1' ...

Having trouble getting the JSON data to work with PHP through $.ajax?

I am currently facing an issue with sending an inline image string to PHP using $.ajax. Despite successfully receiving the server response from PHP, I am unable to retrieve the data sent from JavaScript in PHP using $_POST. Could you please help me ident ...

The functionality of Angular template routing is non-functional

When trying to view my angular project, I want to load a template HTML in my main index.html but all I get is an empty screen. <!DOCTYPE html> <html lang="nl" ng-app="store"> <head> <meta charset="UTF-8> <title>NMDAD- ...

Strategies for resolving a mix of different data types within a single parameter

Here, I am setting up the options params to accept a value that can either be a single string or another object like options?: string[] | IServiceDetail[] | IServiceAccordion[]; However, when attempting to map these objects, an error is encountered: Prope ...

Implementation of the I18next library

I am currently integrating react-i18next into my application to implement a switch button for French and English languages. Unfortunately, I am facing some issues as the translation is not working properly. I suspect it's related to the JSON file reco ...

Tips for updating a single attribute in Mongoose

I am currently using mongoose version 4.1.8 and below is an example of my mongo db schema: (function() { 'use strict'; const mongoose = require('mongoose'); const Schema = mongoose.Schema; const DataCodeSchema = new Schema({ ...

Using the jQuery .each() method to generate an array of objects

I have a goal of creating something similar to this. var data = google.visualization.arrayToDataTable([ ['Year', 'Cost'], ['2004', 1000], ['2005', 1170], ['2006', 660], ['2007&a ...

pause the timer once the interval reaches 0

In order to accomplish the task of stopping the timer once it reaches 00:00 and displaying an alert message saying "countdown stopped", I need to implement a function that will handle this. The timer should start again after the stoppage occurs, which mean ...

I am encountering a problem with the setState function, and receiving the error message: "Cannot read property 'setState' of null"

I need assistance with my code. There seems to be an issue, possibly a syntax error, but I am having trouble pinpointing it: import React, { Component } from 'react'; class Note extends Component { constructor(props) { super(props); t ...

Providing additional parameters to the checkNotAuthenticated function

I am currently working on developing a function to verify if a user is authenticated and redirect them to a specific page if they are. Here is my initial approach: function checkNotAuthenticated(req, res, next, redirect) { if (!req.isAuthenticated()) { ...

Unable to connect to 127.0.0.1 or any other IP addresses, but localhost is accessible

I'm currently utilizing Nodejs and Expressjs. When attempting to access my application through , everything loads correctly. However, when trying any other loopback IP addresses (such as 127.0.0.1, my PC name, or my PC IP), I encounter the following ...

The knockout.js subscribe function isn't activating during the initial set

In my model class, I have defined observables and I am looking to subscribe to their sets. Below is the code snippet that showcases what I currently have: var dto = function (data) { var self = this; self.Value1 = ko.observable(data.Value1); s ...