Working with Aframe: Implementing THREE.LineBasicMaterial into AFrame

While trying to implement LineBasicMaterial in AFrame, I have encountered some issues:

1. Variables are being injected into the schema and cannot be removed without causing errors

I defined a box like this:

<a-box material="shader: linebasic;"></a-box>

Additionally, I registered a custom shader:

AFRAME.registerShader('linebasic', {
    schema: {
        blending:       {default: THREE.NormalBlending},
        color:          {type: 'color', default: 0xffffff, is: 'uniform'},
        depthTest:      {default: true},
        depthFunc:      {default: THREE.LessEqualDepth},
        depthWrite:     {default: true},
        fog:            {default: false},
        linewidth:      {default: 10},
        linecap:        {default: 'round'},
        linejoin:       {default: 'round'},
        needsUpdate:    {default: true},
        opacity:        {default: 1},
        side:           {default: THREE.FrontSide},
        transparent:    {default: true},
        vertexColors:   {default: THREE.NoColors},
        visible:        {default: true}
    },
    init: function (data) {
        console.log(data);
        delete data.flatShading;
        this.material = new THREE.LineBasicMaterial(data);
        this.update(data);
    },
    update: function (data) {
        this.material.clone(data);
    }
});

Despite not having certain properties specified, such as flatShading or shader, they are still present in the data which causes errors. To resolve this, I had to manually remove them.

If I attempt to delete the 'shader' property, an error is thrown stating:

components:material:error Unknown shader schema undefined +0ms

If I keep the 'shader' property, a notice message appears saying:

THREE.LineBasicMaterial: 'shader' is not a property of this material.

It seems that something is amiss either way.

UPDATE of #1:

To address issue #1, I followed @ngokevin's suggestion:

AFRAME.registerShader('linebasic', {
    schema: {
        blending:       {default: THREE.NormalBlending},
        color:          {type: 'color', default: 0xffffff, is: 'uniform'},
        depthTest:      {default: true},
        depthFunc:      {default: THREE.LessEqualDepth},
        depthWrite:     {default: true},
        fog:            {default: false},
        linewidth:      {default: 10},
        linecap:        {default: 'round'},
        linejoin:       {default: 'round'},
        needsUpdate:    {default: true},
        opacity:        {default: 1},
        side:           {default: THREE.FrontSide},
        transparent:    {default: true},
        vertexColors:   {default: THREE.NoColors},
        visible:        {default: true}
    },
    init: function (data) {
        data = AFRAME.utils.extend({}, data);
        delete data.flatShading;
        delete data.shader;
        this.material = new THREE.LineBasicMaterial(data);
        this.update(data);
    },
    update: function (data) {
        this.material.clone(data);
    }
});

2. LineBasicMaterial renders as a solid white block

Even with all the required properties set for THREE.LineBasicMaterial, I'm facing an issue where the material displays as a solid block instead of lines.

Solution is elusive since neither Material nor LineBasicMaterial contain 'wireframe'. This leaves me uncertain about how to proceed without resorting to unconventional methods.

Fixing issue #2 takes precedence for me currently, but resolving #1 is also important as I believe they might be interlinked, hence posing both questions together.

Answer №1

Regarding question #1, it's important to note that the current setup allows for direct access to the data object. Instead of deleting this access, it is recommended to clone the object and then proceed with deletion. A potential improvement has been identified which involves using this.data directly rather than through a function call.

data = AFRAME.utils.extend({}, data);

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

Troubles encountered while processing STL file readers

Utilizing STLLoader.js, I am able to render components successfully, however, they all appear with one uniform color which does not resemble real-world components. The image above showcases my implementation in Three.js using STLLoader.js (Binary STL file ...

The jQuery code does not execute following the use of window.location.replace( url ) command

I'm facing an issue with my code that involves redirecting the page to the index page after clicking on a specific link ('#versionPageFromProdLink'). The index page contains certain content within a div, which I want to hide once the redirec ...

Is it advisable to use npm devDependencies in a production environment?

While reviewing the package.json file for one of our products at work, I noticed that the SDK uses socket.io for a crucial function even though socket.io-client is listed as a devDependency. Despite this discrepancy, the SDK works flawlessly for our clie ...

How can we verify the validity of URLs based on their length, presence of capital letters, and specific whole words?

I'm currently working on a piece of code that verifies the URL provided by users during sign-up for my application. I want to implement the following restrictions: URL must be at least 3 characters long No capital letters allowed Avoid certain words ...

Encountered a setback while trying to add information to a MySql database through Express

When I try to execute an insert query on a database, it throws the following error: code: 'ER_PARSE_ERROR', errno: 1064, sqlMessage: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio ...

"Enhancing User Experience with AngularJS by Dynamically Modifying and Refresh

I'm currently attempting to dynamically add HTML elements using JavaScript with a directive: document.getElementsByClassName("day-grid")[0].innerHTML = "<div ng-uc-day-event></div>"; or var ele = document.createElement("div"); ele.setAttr ...

How can we prevent users from changing URLs or accessing pages directly in Angular 7 without using authguard?

Hey there! I am trying to find a way to prevent users from accessing different pages by changing the URL, like in this https://i.sstatic.net/E2e3S.png scenario. Is there a method that can redirect the user back to the same page without using Authguard or a ...

Using Jquery to toggle visibility and position of a button when clicked

I'm new to using Jquery and I've been able to create a button that shows a div and moves the button to the right when clicked. I have looked at similar questions about toggling visibility, but I also need to move the button back when it's cl ...

Unable to initiate the server generated by the express.js generator

Currently, I am trying to set up an Express.js server using their generator. Following the documentation, I was able to successfully create the basic structure. However, when attempting to run the prescribed command (SET DEBUG=transcriptverificationserver: ...

Convert JavaScript objects into HTML format

Alright, I've got some JavaScript that's fetching data from a JSON file through a URL. Now, my goal is to convert each object (author_name, rating, author_url) into JavaScript IDs so that I can easily reference them in my HTML. For instance: &l ...

Tips on allowing a rectangle to be draggable using HTML5

I have been experimenting with resizable and draggable rectangles in HTML5. I've managed to create resizable rectangles, but I am having trouble getting them to drag using mouse events. You can view my JSFiddle code at the following link: here. / ...

Utilize JavaScript to send an email containing a link and content

In the html form, there are input fields for adding a new user to the database. Once a user is added, an email is sent to them using the sendmail() function in the adduser.js file. The email is sent successfully according to my standards. However, I want t ...

NodeJS does not support the Array.Push method

I'm having trouble getting this code to work. I want to generate 5 random items from my database and store them in an array called 'dato'. However, when I print the array, it appears to be empty. /* GET users listing. */ router.get('/& ...

How can I ensure the keyboard does not cover the text input in React Native?

I am trying to figure out how to keep the keyboard from covering the text input field and instead have it appear below. Every time I type something, the keyboard obstructs my view of the text box content. Any help in solving this issue would be greatly a ...

fancybox is slightly off-center

I am currently using fancybox 1.3.4 to display some content in a popup window, but I am facing an issue where the popup is not centered in the browser. Can anyone help me with fixing this problem? Here is the HTML code snippet: <a class="clickMe" titl ...

Having difficulty generating bcrypt password hashes in Node.js

I am facing an issue with the following code. I am attempting to hash my admin password when they register. The password is initially set to a default value via the mongoose schema. However, the hashing process seems to not be working correctly. Below ar ...

What are the implications of a project containing nested node_modules directories?

We are currently in the process of dividing our project into "sub modules" within a single repository. Our goal is to maintain aspects such as webpack configurations and express server globally, with a structure similar to the following: package.json serv ...

Vue's dynamic component list now accurately removes incorrect HTML nodes

Exploring the capabilities of Vue.JS by creating components dynamically and composing them together. Encountered an unusual issue where, even though data seems to be updating correctly, removing one of the boxes using splice() always results in the remova ...

The battle between AngularJS, Factory, $scope, and promises intensifies

Currently facing a challenge with the code snippet below: app.factory('sfAttachment', ['$http', '$q', '$window', '$rootScope', function($http, $q, $window, $rootScope) { var attachment = {}; //Functio ...

ReactJS Form: Updates in Parent Component State Result in Child Field Being Cleared and Props Remaining Unchanged

I have devised a ReactJS code for an interactive form that allows the collection of student details. The beauty of this form is that it can accommodate any number of students with ease. In this setup, the parent component is known as App and the child comp ...