three.js; Encountering an issue with accessing the 'position' property of an undefined object and unable to determine the cause

Creating my own SUN!!!!!!!!! SUNGOD!!! urg---!

Oops, didn't quite work out.

An error message appeared on the console:

// Uncaught TypeError: Cannot read property 'position' of undefined;

Here is the source code:

// Building * The Solar *
var shape = new THREE.BufferGeometry();
    shape.addAttribute('position', new THREE.Float32Attribute(6,3));
    // The issue seems to be here but I'm not sure where
    shape.addAttribute('textureOrder', new THREE.Int8Attribute(6,1));


    for(var i=0; i<6; i++) {
        shape.attribute.position.setXYZ(i, 0, 0, 0);
        shape.attribute.textureOrder.setX(i, i);
    };

var d = new Date();

var material = new THREE.ShaderMaterial({
    uniforms: {
        time: { type: 'f', value: d.getTime() },
        tsun_core: { type: 't', value: loadTexture('./sun_core.png') },
        tsun_innerglow: { type: 't', value: loadTexture('./sun_innerglow.png') },
        tsun_starlight: { type: 't', value: loadTexture('./sun_starlight.png') },
        tsun_outerglow: { type: 't', value: loadTexture('./sun_outerglow.png') },
        tsun_shortjetlight: { type: 't', value: loadTexture('./sun_shortjetlight.png') },
        tsun_longjetlight: { type: 't', value: loadTexture('./sun_longjetlight.png') }
    },
    vertexShader: document.getElementById('vs-sun').textContent,
    fragmentShader: document.getElementById('fs-sun').textContent
});
    material.depthTest = false;
    material.vertexColor = true;
    material.transparent = true;
    material.blending = THREE.AdditiveBlending;

sun = new THREE.ParticleSystem(shape, material);
scene.add(sun);

My aim is to adjust gl_FragColor opacity using uniform time in the fragment shader to make my sun(?) more dynamic...

In my opinion, the problem lies somewhere in the code above. Any guidance would be appreciated..

Answer №1

Utilizing the addAttribute method on an instance of THREE.BufferGeometry will generate properties within the attributes container, rather than attribute.

Replace these statements

    shape.attribute.position.setXYZ(i, 0, 0, 0);
    shape.attribute.textureOrder.setX(i, i);

With the subsequent content

    shape.attributes.position.setXYZ(i, 0, 0, 0);
    shape.attributes.textureOrder.setX(i, i);

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

Is there a problem with Angular2 using TypeScript?

Currently, I am in the process of setting up my machine for Angular development by following the guidelines provided on https://angular.io/docs/ts/latest/quickstart.html As I proceeded to run "npm start" to launch my site, I encountered an issue with the ...

Searching and replacing query strings in a URL using JQuery according to the chosen option in an HTML dropdown menu

Is there a way to use jQuery to dynamically change a specific value in the query string by finding and replacing that value based on the selection made from a dropdown menu on the webpage? For example: Imagine we have this query string on the current page ...

Having issues with Angular Material, specifically with mat-list-item and routerLinkActive not functioning as expected

Currently, I am working with a navigation view that utilizes the MatSidenavModule. The issue I am encountering is on mobile screens. When I click a mat-list-item, the mat-sidenav closes as expected. However, upon opening the mat-sidenav again, Material alw ...

I am encountering an issue where my useState value is coming back as undefined after I fetch data. It appears that the useState hook is

import React, { useEffect, useState } from 'react'; function MainContent() { const [objectsArr, setObjectsArr] = useState(null); useEffect(() => { async function fetchData() { let response = await fetch('http ...

How to Use Angular 8 to Filter an Array of Objects Based on Numeric Values

Can the list be filtered based on the value of iseidaCcaa.id? var centers = [ { id: 2, nombre: "Centro 2", iseidaCcaa: { id: 1, }, }, { id: 3, nombre: "Centro 3", iseidaCcaa: { id: 1, }, }, { id: 1 ...

Ways to identify the current version of webpack installed

Currently in the process of utilizing Webpack to transpile and bundle multiple JS files. I am curious about determining the specific version that I am using. In this scenario, assuming that it is globally installed, how can I identify the version without ...

Rearranging the img element within the dom structure to optimize display in various blog posts

Hey there, I have a specific task that I need help with: Currently, I am using Business Catalyst as my framework. They have a blog module that does not offer much customization when it comes to blog lists. There is a preview tag that displays a preview of ...

What is the solution for the error message "TypeError: null is not an object (evaluating 'AgoraRtcChannelModule.prefix')"?

When attempting to import RtcEngine into my application with the line import RtcEngine from 'react-native-agora';, I consistently encounter the following error message: AgoraRtcChannelModule.prefix' is not an object (TypeError) at node_modul ...

In what location can event listeners be found in npm packages?

For a while now, I've been immersed in the world of coding as I work on creating my very own IRC bot using nodejs. This project serves as an invaluable learning experience for me, and as I navigate through the process, I constantly encounter event lis ...

Tips for stopping Vue.js automatic merging of CSS classes

Recently, I embarked on my journey with Vue.js and have been thoroughly enjoying the experience. However, I've stumbled upon a challenge that has me stumped. Despite searching high and low and studying the documentation, I haven't found a solutio ...

Sending a date via an input date control while bypassing the onkeydown event with "return false" in Selenium Python

Looking at the simple HTML structure below: <!DOCTYPE html> <html> <body> <input type="date" max="2023-03-09" value="2023-03-09" onkeydown="return false"> </body> </ht ...

Getting the Test case log from Soap UI is a simple process that involves following a

Looking to extract the response time for each step from the TestCase Log when a specific Test case or TestSuite is executed. Can someone provide guidance on how to achieve this using a Groovy script? ...

Trouble with launching Semantic UI modal

I have implemented a button using Semantic UI and set up a click event to open a modal when clicked, but nothing is happening. When I click on the link, there is no response. I'm unsure what the issue might be. Below is the code for the button: < ...

Variability in the console output upon shutting down the express server

As part of a university module, I am currently developing a Node/Express web application. The structure of my project includes three main files: db.js, app.js, and entry.js. The db.js file is responsible for creating a Sequelize instance and exporting it ...

Using AJAX to pass post variables

Here is a link I have: <a class="tag" wi_id="3042" wl_id="3693" for_user_id="441" href="#a"> This link triggers an ajax call. $(".tag").click(function() { var for_user_id = $(this).attr("for_user_id"); var wl_id = $(this).attr("wl_ ...

Organizing form data using Vue

One of the features of my code is the ability to create dynamic input and select elements: <div v-for="(index) in rows"> <select> <option selected="true" disabled>Select Type</option> <option>Name</opti ...

AngularJS is in need of a properly formatted print layout, as the current

Currently, my code looks like this: <li ng-repeat="items in ferdigheter">{{ items.title}} <div class="circles"> <div class="circle" ng-repeat="a in thisnumber(items.stars)"></div> <div class="empty_circle" ng-repeat="a i ...

Error: The function this.$.AjaxPost.go is missing or not recognized in the core-ajax module

Recently, I created an HTML page for handling Password Reset functionality on our website. We have decided to make POST calls to the server and are implementing it using polymer. Below is a snippet of the code: <dom-module id="user-password-reset"> ...

Capture the Promise Rejection

During my test with WebdriverIO, I consistently encounter an issue specifically with this line of code: await browser.waitForVisible('#tx-sent li', 15000) Intermittently, a Promise rejection error occurs: Error: Promise was rejected with the ...

Is there a way to sort through an array based on a nested value?

Within an array of objects, I have a structure like this: "times": [{ "id" : "id", "name" : "place", "location" : "place", "hours" : [ {"day": " ...