A beginner's guide to implementing InstancedBufferGeometry in threejs

I am encountering an issue where the polygon is not being displayed when using InstancedBufferGeometry, even though it is shown when using BufferGeometry.

Can anyone help me understand why the code below is not functioning as expected?

Please provide guidance on how to resolve this issue.

const createGeometry = () => {
    // const geometry = new THREE.BufferGeometry();
    const geometry = new THREE.InstancedBufferGeometry();
    const positions = new THREE.BufferAttribute(new Float32Array(4 * 3), 3);
    const uvs = new THREE.BufferAttribute(new Float32Array(4 * 2), 2);

    positions.setXYZ(0, -0.5, 0.5, 1.0);
    positions.setXYZ(1, 0.5, 0.5, 1.0);
    positions.setXYZ(2, -0.5, -0.5, 1.0);
    positions.setXYZ(3, 0.5, -0.5, 1.0);
    uvs.setXYZ(0, 0.0, 0.0);
    uvs.setXYZ(1, 1.0, 0.0);
    uvs.setXYZ(2, 0.0, 1.0);
    uvs.setXYZ(3, 1.0, 1.0);
    geometry.setAttribute("position", positions);
    geometry.setAttribute("uv", uvs);

    geometry.setIndex(
      new THREE.BufferAttribute(new Uint16Array([0, 2, 1, 2, 3, 1]), 1)
    );

    return geometry;
  };

The issue arises when trying to display the polygon with BufferGeometry.

Answer №1

It is essential to include at least one InstancedBufferAttribute when utilizing an InstancedBufferGeometry.

The lack of these attributes does not align with the purpose, as they are necessary to specify variations for each instance.

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

What is the recommended placement for the implicitlyWait method in Protractor?

When implementing implicitlyWait, what is the appropriate location to include browser.manage().timeouts().implicitlyWait(5000); within the test script? ...

Displaying certain elements in reduced resolution

I have integrated a costly ocean shader () into my project, which unfortunately leads to a significant drop in user experience on older mobile devices (from 60fps to 20fps). To counteract this performance issue, I have optimized the renderer by setting a l ...

Input the selected checkbox options into the designated text field

My form consists of 3 arrays of checkboxes - hummus[], mayo[], jam[]. Currently, the jQuery functions disable the remaining checkboxes once the required number is checked. Query: I am attempting to transfer the values of the checked checkboxes into text f ...

Using absolute positioning on elements can result in the page zooming out

While this answer may seem obvious, I have been unable to find any similar solutions online. The problem lies with my responsive navbar, which functions perfectly on larger screens. However, on mobile devices, the entire website appears zoomed out like thi ...

`Uniform background color across all pages`

My goal is to allow customers to select a color that will persist across different pages on the website. The code below shows how users can choose a color on the first page: <select id="color" style="width: 5%; height: 10%" size="5"> ...

Input for uncomplicated changing identifier

I am looking to create types for dynamic keys that will be of type number. I have two similar types defined as follows: type UseCalculatePayments = () => { totalPayments: number; aggregate: number; condition: boolean; }; type UseCalculateCommissio ...

Developing a innovative and interactive nested slider using Jssor technology

Trying to implement a dynamic jssor nested slider to showcase albums and images from a mySQL database. Everything works fine with a single album, but when there are two or more albums, the display gets messed up. I'm still learning JavaScript and JQue ...

Evaluating the use of promise in Angular using Jasmine testing

I'm currently troubleshooting whether a method with a promise is being properly called Below is the snippet of my controller code: app.controller('StoresListController', function ($scope, StoresService) { $scope.getStores = function ( ...

Adjust Element Width Based on Scroll Position

I'm attempting to achieve a similar effect as seen here: (if it doesn't work in Chrome, try using IE). This is the progress I've made so far: http://jsfiddle.net/yuvalsab/op9sg2L2/ HTML <div class="transition_wrapper"> <div ...

Error: TypeScript is unable to find the property URL within the specified type. Can you help

Currently, I am honing my skills in TypeScript and encountering a problem. I am a bit confused about how to define the type for the URL when I am setting the mix here. Obviously, the URL is supposed to be a string, and this specific scenario is within the ...

Change the color of a bar chart in chart.js depending on the value it represents

function findMaxIndexes(array, n) { const maxValues = array.slice().sort((a, b) => b - a).slice(0, n); return array.map((x, i) => [x, i]).filter(pair => maxValues.includes(pair[0])).map(pair => pair[1]); } // dummy data var data = [12, 19, ...

The page refreshes when the anchor element is clicked

Currently, I am working on enhancing a web application that is built on the foundation of traditional aspx (asp.net) web forms with elements of Angular 6 incorporated into it. My current assignment involves resolving a bug that triggers a page refresh whe ...

Having trouble integrating document.getElementById('password').addEventListener() in a webpack and ES6 environment

I have a project where I am utilizing webpack and ES6 classes. In this particular scenario, I am attempting to trigger the 'onblur' function on input#password but unfortunately, it is not working as expected. Strangely, there are no errors thrown ...

Having difficulties with implementing the throw await syntax in an async express handler in Node.js

const express = require("express"); const expressAsyncHandler = require("express-async-handler"); const app = express(); const func = async () => { return false; }; app.get( "/", expressAsyncHandler(async () => ...

Enhancing chosen meshes through post-processing techniques

Is it feasible in three.js to exclusively use postprocessing effects on specific meshes? For instance, having a cube with a grain effect while the surrounding scene remains unaffected. Appreciate any insights! ...

Vue.js: click event does not trigger transform animation

I am facing a challenge with rotating an arrow icon within a dropdown menu. Despite my efforts, the rotation does not synchronize with the appearance of the dropdown menu. Here is the Vue component code snippet: <nav> <section class= ...

Using jQuery to send a POST request with a data object

Trying to figure out something. Attempting to post an object using jQuery Ajax POST, like so: var dataPostYear = { viewType:GetViewType(), viewDate:'2009/09/08', languageId:GetLanguageId() }; $.ajax({ type: "POST", url: url ...

Jade not responding to AngularJS click directive function

This tutorial is inspired by the MEAN Stack demo: Mongo, Express, AngularJS, and NodeJS I am attempting to incorporate a 'delete' method into my controller in the Jade template as shown below: characters.jade script function CharactersCont ...

Is there a way to showcase a block of Python code using a combination of HTML, CSS, and Javascript to enhance its

On my website, I want to display code blocks similar to how StackOverflow does it. The code block should be properly colored, formatted, and spaced out for better readability. All the code blocks on my site will be in python. def func(A): result = 0 ...

Transforming a flow type React component into JSX - React protocol

I have been searching for a tooltip component that is accessible in React and stumbled upon React Tooltip. It is originally written in flow, but I am using jsx in my project. I am trying to convert the syntax to jsx, but I'm facing difficulties with t ...