Assistance needed with the usage of static and dynamic ArrowHelper in Three.js

I am facing an issue with two different code snippets for drawing a vector along a direction defined by the directionVectorLocal vector.

The first snippet is as follows:

var transportedVector = {
    coordLocal,
    arrowHelper,
    directionVectorLocal,
    directionVector
};

var arrowHelperTest = new THREE.ArrowHelper(transportedVector.directionVectorLocal.normalize(), originLocalBasis, 100);
camera.add(arrowHelperTest);

In this case, the arrow arrowHelperTest appears correctly on the scene.

Now, moving on to the second snippet:

var arrowHelper;
var transportedVector = {
    coordLocal,
    arrowHelper,
    directionVectorLocal,
    directionVector
};

transportedVector.arrowHelper = new THREE.ArrowHelper(transportedVector.directionVectorLocal.normalize(), originLocalBasis, 100);
camera.add(transportedVector.arrowHelper);

In this case, the arrow transportedVector.arrowHelper does not appear.

To resolve this issue, I have found that declaring "var arrowHelper;" just before defining the transportedVector object prevents a "

ReferenceError: arrowHelper is not defined
" error.

I am looking for a way to dynamically declare and define transportedVector.arrowHelper within the transportedVector object and display it in the scene. Any insights or solutions would be greatly appreciated.

Thank you.

Answer №1

Refer to my response on your initial post. The following code seems to be functioning correctly in the scenario I tested:

let directionVectorLocal = new THREE.Vector3(0,0,-1);
let originLocalBasis = new THREE.Vector3(0,0,0);
let transportedVector = {
    arrowHelper: null,
    directionVectorLocal: directionVectorLocal
};

transportedVector.arrowHelper = new THREE.ArrowHelper(transportedVector.directionVectorLocal.normalize(), originLocalBasis, 100); // Ensure the arrow's length is greater than the camera's zNear value for visibility.
camera.add(transportedVector.arrowHelper);
scene.add(camera);

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

How can cookies be managed with JavaScript, Express.js, or Node.js?

Could anyone advise on the optimal approach for managing cookies - through Express.js, Node.js, or client-side JavaScript/jQuery? I'm feeling a bit uncertain about security implications. Your assistance and insights are greatly appreciated. ...

Ways to effectively go through local storage using a loop

I'm currently working on enhancing my navbar by adding links based on searches made by users and their favorite selections. My goal is to avoid duplicate entries in the "past searched" section if the current search already exists in the list. I'm ...

Does the rendered ID of an ASPX control always appear the same in the source HTML code?

Let's say I have an aspx textbox with id="txtkms". In the HTML view source, it appears as ContentPlaceHolder1_Gridview1_txtkms_1. I'm curious if this control will always be rendered as ContentPlaceHolder1_Gridview1_txtkms_1 every time I run my as ...

Issues with Select2 Ajax functionality not functioning as intended

I am currently using the select2 library to create a dropdown menu with ajax functionality, but I am encountering some issues. Below is my code: $("#guests").select2({ multiple: true, minimumInputLength: 1, formatInputTooShort: fun ...

Unable to connect to Server API endpoint

Encountering an issue while trying to access the API endpoint from server.js that connects to Spotify API. Below is my server.js code: // server.js const express = require('express'); const app = express(); const dotenv = require('dotenv&apo ...

Using AngularJS to fetch Google OAuth2 tokens

Every time I initiate this call, it triggers the account selector to open. Following which I can choose one of my Google accounts, but upon selection, an error occurs. Error: invalid_request Missing required parameter: scope The URL in the account selec ...

Is it possible to create a cylinder in three.js that emits light, giving it the appearance of a tube light?

As a beginner in Blender and three.js, I am eager to find resources that can help me master the art of creating scenes in Blender and then exporting them to three.js. I've noticed that in Blender it's possible to make any mesh emit light - how ca ...

Utilize a vanilla JavaScript object as the primary model in Ember

Can a plain JS object, such as a literal object, be used as a model in EmberJS? I've noticed that all the examples in the documentation utilize Ember.Object or a datastore. I understand that I may not have access to features like observables with pl ...

Navigating with React Router Dom and parsing objects in search parameters

Currently, I am utilizing React Router Dom v6 and require the ability to retain object search parameters within the URL. My current approach involves: const [searchParams, setSearchParams] = useSearchParams(); const allSearchParams = useMemo(() => { ...

I encountered some problems with conflicting Angular dependencies, so I decided to delete the node_modules folder

An error has occurred: The module 'H:\All_Files\Scripts\Angular\example\node_modules\source-map\source-map.js' could not be found. Please ensure that the package.json file contains a correct "main" entry. ...

Adding elements to an array or object in JavaScript using the same key for each item

I am currently using DataTables and attempting to dynamically generate the "aoColumns" values in order to avoid hard-coding them. After trying out a particular approach, it appears that I may be incorrectly overwriting the same key in each row rather than ...

Learning how to pass multiple rows of data using d3 is essential for effective data

Here is some code that I am working with: var row = 4; var col = 4; var stack = d3.layout.stack(); var layers = stack( d3.range(row).map(function() { return CmcLayer(col); })); function CmcLayer(col) { var a = [1, 2, 3, 4]; return a.map(func ...

How can we use jQuery to compare two blocks and set them to have the same height value?

Is there a way to compare and set equal height for two blocks within the main div? <div class="main-content"> <div class="content-1"></div> <div class="content-2"></div> </div> Javascript Code: var $content1 = $(&ap ...

I duplicated a functional jQuery form and moved it to a different location, but I am only able to get the

I recently duplicated a jQuery form from one page to another, but encountered unexpected issues with the copied version. The original form functions as follows: An onclick function connected to an image triggers a confirmation modal window with an "OK" bu ...

Utilizing the dnd library to incorporate drag and drop functionality

I've encountered an issue with the code snippet below. Although I am able to drag elements, I am unable to drop them. How can I trigger the dropFunction when a drop occurs? Drag code: <div> <a class="button" ng-class= ...

Invoke two functions simultaneously on a single Onchange event

Can someone help me understand how to trigger two functions by changing the value of a specific dropdown list using the "OnChange" event in Ajax? Note: The system typically only displays the output of the showhistory() function. Here is my existing code: ...

The rate of increase decreases as the value approaches its maximum assignment

Visualizing this question requires some pseudo-code, so here it is: Imagine I have two integers - one variable and one constant. int current = 0; static int max = 20 My goal is to add slowly as I approach 20, never actually reaching it. For example, if ...

Data in the XMLHttpRequest Post method is failing to be transmitted

This is the code snippet in JavaScript: function eAC(emailData) { if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); } if (!httpRequest) { return false; } console.log(emailData); var fd = new FormDa ...

Is there a way to retrieve the disabled drop-down field value after submitting the form?

I'm struggling with a dropdown field that becomes disabled once an item is selected. After submitting the form, the dropdown field loses its value and I'm left with an empty field. Any suggestions on how to keep a value in the dropdown after subm ...

I am interested in deleting an element from Firebase using JavaScript

I'm struggling to grasp the concept of deleting an item from my Firebase database. I have successfully created a function (saveEmployee) to add items, but removing them is where I hit a roadblock. HTML <tbody ng-repeat="employee in employees"> ...