Developing a fresh entity in the world of three.js

Currently engaged in a project that involves creating 3D objects using Three.js, sourced from databases.

The connection is established, but encountering failures when attempting to generate a new object.


this.type = 'CustomObject';
let shape = new THREE.Shape();
const maxSize = coords.reduce((prev, current) => (Math.abs(prev.value) > Math.abs(current.value)) ? prev : current); // max Size but Abs

// Check whether maxSize is positive or negative.
let height = Math.abs(maxSize.value);

shape.moveTo(0, 0);
for (let i = 0; i < coords.length; i++) {
    shape.lineTo(coords[i].id, coords[i].value);
}

shape.lineTo(coords[coords.length - 1].id, -height - 3);
shape.lineTo(0, -height - 3);
shape.lineTo(0, 0);

let extrudeSettings = {
    steps: 4,
    amount: 20,
    bevelEnabled: false,
    bevelThickness: 1,
    bevelSize: 1,
    bevelSegments: 1
};

this.geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
this.material = new THREE.MeshBasicMaterial({color: 0xCbcbcb});
let object = new THREE.Mesh(this.geometry, this.material);
this.createdGraph = object;
console.log(this.createdGraph.Object3D);
this.scene.add(this.createdGraph);

This snippet of code may not be perfect, but I wish to debug it before refining it further. It's written with ES6 features in mind.

The issue arises when attempting to integrate the created figure into A-Frame, as it keeps throwing an error stating 'you can't add an object without an Object3D to the scene' or 'this.updateMorphTargets is not a function'.

If anyone has any insights or solutions to offer, they would be greatly appreciated.

Additional details regarding attempted fixes can be found here, but they also result in the same 'this.updateMorphTargets is not a function' error.

Thank you for your assistance!

Answer №1

I'm uncertain which parts are causing the issue,
I've duplicated your code to a fiddle, included 3 coordinates, and it's functioning.

Based on your code, it seems there are incorrect scene references in A-Frame:

this.el.sceneEl

assuming this refers to any entity, and not this.scene.
Additionally, refer to three.js objects as object3D, not Object3D


I have isolated the creation of the three.js object to an A-Frame component:

AFRAME.registerComponent("bar",{
  init:function(){
  //Insert your code here
  }
});

and added an entity for testing:

<a-entity bar> </a-entity>


I have also positioned the object by accessing the scene reference before adding it:

this.el.sceneEl.object3D.add(object)

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

Using Bootstrap tooltips in an Ajax request

While validating a form with tooltip and performing an AJAX call for the backend response along with an alert message, I encountered an issue. The problem was that even when the text was empty, it still validated and proceeded to the AJAX success call. H ...

"What is the most efficient way to break up an array into its maximum length and iterate over

Using Firebase to send push notifications, but encountering the following error: { Error: tokens list must not contain more than 500 items at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42: ...

One div takes a backseat to the other div

I recently delved into learning Bootstrap, but I'm baffled as to why one div is appearing behind another. <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Fa ...

Are there any security concerns involved in creating a game using a combination of JavaScript, Electron, and Three.js?

I'm not looking to create anything on the scale of an MMORPG, just a small game similar to Faster Than Light. Is there a way to protect against cheat engine or prevent users from running their own JavaScript in the game, considering anyone can access ...

The dazzling world of first person animations with three.js

In the process of creating a first-person game in three.js, I am aiming to incorporate movement in the gun when the player commands actions like walking or shooting. Despite being a novice in three.js and lacking knowledge on animation techniques using ani ...

Loading indicator displayed at the top of a div using JavaScript/jQuery

My current challenge involves implementing a progress bar, similar to the pace.js progress bar. The issue arises when the browser is refreshed, as the pace.js progress bar loads on top of the body instead of within a specified div. It is important that the ...

A strategy for concealing the selected button within a class of buttons with Vanilla JS HTML and CSS

I have encountered a challenging situation where I am using JavaScript to render data from a data.json file into HTML. Everything seems to be functioning correctly, as the JSON data is being successfully rendered into HTML using a loop, resulting in multip ...

Strategies for removing duplicate items from an array of objects

My array consists of objects with the following structure: $scope.SACCodes = [ {'code':'023', 'description':'Spread FTGs', 'group':'footings'}, {'code':'024', 'de ...

Tips for determining the number of columns in a multi-column web layout using webkit

Having some static HTML content that needs to be formatted using multiple columns, which are presented as pages to the user. The method used is quite simple: bodyID = document.getElementsByTagName('body')[0]; bodyID.style.width = desiredWidth; t ...

Reusing methods in Javascript to create child instances without causing circular dependencies

abstract class Fruit { private children: Fruit[] = []; addChild(child: Fruit) { this.children.push(child); } } // Separate files for each subclass // apple.ts class Apple extends Fruit { } // banana.ts class Banana extends Fruit { } ...

When you click on the element, data is initially loaded through an ajax request. Subsequent clicks will not trigger any additional ajax requests

$.ajax({ type: "POST", url: "/php/auth/login.php", data: $("#login-form").serialize(), success: function(response) { // do something with the response }, complete: function() { ...

Choose the parent element within an Angular application

I need help selecting the parent element (searchres) in Angular and applying styles to it. Here is my HTML code: <div ng-repeat="product in products" class="searchres"> <a href="#"> <img src="{{product.path}}" cla ...

Attain worldwide reach

I'm currently facing a Scope issue that has been quite challenging to resolve. The saying goes, "a picture is worth a thousand words," and in this case, it couldn't be more true. Whenever the OK or REJ buttons trigger the reject() function, passi ...

What measures can be taken to avoid RowIDs resetting in jqGrid?

After each pagination action (such as increasing the number of rows or moving to the next page), I noticed that the rowIDs get reset for some reason. For example, let's say I have a total of 75 records. I am displaying 15 records per page, resulting ...

"Exploring the concept of undefined within object-oriented programming and its role in

Recently diving into Express and trying out routing by creating an object in a file to export. import userController from "../controllers/userController.js" // get all users router.get("/", isAuth, isAdmin, userController.list) Encoun ...

Searching for a jQuery plugin that can dynamically rearrange tables while automatically updating their corresponding IDs

Is there a way in jQuery to dynamically move tables around on a webpage? Currently, I have implemented a button that clones a hidden table when needed and another button to delete unwanted tables. Now, I am looking to incorporate a feature that allows the ...

I am eager to prevent my division element from shifting position

I have a program that controls the water level in a virtual bottle. By clicking a button, the water level can increase or decrease. However, the program does not automatically stop; it requires manual intervention to stop it. I need to modify it so that wh ...

Updating the selection without refreshing the page

Whenever I change the value, my page refreshes because I need to send the value to query data. However, my selector does not display the value when selected. <form name='active' action='' method='GET'> <select class= ...

Response received from the server

I am looking to display server response error messages within a form after submission. By using the following code in my JavaScript, I am able to retrieve the error message: .error(function (data, status, header, config) { $scope.postDataSuccessfully ...

The functionality of JQuery fails to work properly when receiving an AJAX response

I have separated my code into three main sections: a PHP file, a jQuery section with an AJAX function that requests data, another PHP file. The response from the AJAX request is HTML that needs to be added at the beginning of a specific DIV inside the i ...