Enhancing the Wireframe Design

Is there a way to display both the wireframe and the object itself, with vertices that update continuously using a shader?

My code currently looks like this;

var mainGeo = new THREE.SphereGeometry(100, 80, 80);
var shaderMaterial = new THREE.ShaderMaterial({
  transparent: true,
  uniforms: displacementUniforms,
  vertexShader: document.getElementById('displacement_vertex').textContent,
  fragmentShader: document.getElementById('displacement_fragment').textContent,  
});

myObject = new THREE.Object3D();

objectLayer1 = new THREE.Mesh(mainGeo, shaderMaterial);
objectLayer2 = new THREE.LineSegments(
  new THREE.WireframeGeometry( objectLayer1.geometry ),
  new THREE.LineBasicMaterial({
    color: 0xff5555,
    transparent: true,
    opacity: 0.5
  })
);

myObject.add(objectLayer1);
myObject.add(objectLayer2);
scene.add(myObject);

update();

updateRender(){
  //RenderScene
  //RenderShaderSourceScene
}

update(){

  //perform necessary actions

  updateUniforms();
  updateRender();

  requestAnimationFrame(update);
}

updateUniforms(){

  //adjust shader uniform values

}

I attempted to use wireframeGeometry but I encountered difficulties updating its vertices.

For instance, I created this object with a displacement shader and am now changing its values over time.

https://i.sstatic.net/C47QU.png

Now, my objective is to display a wireframe around the object while also being able to modify properties such as width, color, and opacity of the wireframe.

What steps can be taken to achieve this?

Thank you in advance.

Answer №1

Success! I have solved the problem!

    The next step is to create a new THREE.LineSegments object using the geometry of objectLayer1 and the shaderMaterial.

However, we are facing a color discrepancy at this point.


UPDATE: Great News!

To address the issue where my linesegments were not displaying the correct colors as per the shader-generated values, I crafted a custom fragment shader to properly recolor the line segments.

Below is the solution:

uniform vec3 lineSegmentColor;

void main() { 
  gl_FragColor = vec4( lineSegmentColor, 1.0 );
}

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 best way to utilize useEffect solely when the length of an array has

Is there a way to trigger a state update only when the length of the prop "columns" changes? useEffect(() => { if (columns.length !== prevColumns.length) { // update state } }, [columns]); Any suggestions on how to achieve this? ...

React with TypeScript: The struggle of getting LocalStorage to work

Currently, I am dealing with persistence in a todo application developed using React and TypeScript. To achieve the desired persistence, I have implemented localStorage. Allow me to share some code snippets: const [todos, setTodos] = useState<todoMod ...

Crafting a clever smart banner using jquery.smartbanner for Android Firefox users

In order to display smartbanners on my mobile website, I utilize jquery.smartbanner. This implementation has been successful for ios, windows phone, and the default android browser. However, when testing on Firefox for android, the smartbanner is not visib ...

What is the best way to apply "display: none;" on a span element nested within a title attribute?

I am utilizing the social-share-button gem to share blog posts on social media. The website has been internationalized, making it bilingual (English and German). Everything is functioning correctly, but I encounter an issue with the social share buttons wh ...

Utilizing ng-bind-html alongside ng-controller

Injecting insecure html into a <div> is part of my current task: <div class="category-wrapper" ng-bind-html="content"></div> The angularjs "code" in this html snippet ($scope.content) includes the following: <script type='text/ ...

Having trouble with Bootstrap 4 dropdowns: Uncaught TypeError issue?

I am having trouble getting my Bootstrap 4 dropdown menu to function correctly. Despite trying various solutions from other threads, I continue to encounter an 'uncaught TypeError: cannot read property 'fn' of undefined' error in bootst ...

Make sure to enable contentEditable so that a <br> tag is inserted

When using a contentEditable, it automatically wraps words to create a new line once the width of the editable area is reached. While this feature is useful, I am facing an issue when parsing the content afterwards as I need it to insert a <br> tag ...

Activate text-entry fields after a button has been pressed on polymer 1.0

I am currently developing a project focused on creating a list of doctors using the Polymer 1.0 framework. Within the doctor-list, I have integrated a Vaadin grid called doctors-grid.html to display data sourced from a JSON file. Upon double-clicking on a ...

Developing a Highchart Graph using JavaScript

I am trying to develop a high chart graph. Check out my code on FIDDLE LINK. I have two values, a and b, for the x-axis and y-axis. The issue arises when the difference between a and b is minimal, such as when both are equal (-9). In such cases, the grap ...

What is the best way to have a single item in a list displayed in two columns?

Can the angular repeat achieve this functionality? I am looking to loop the two elements together. Any assistance would be greatly appreciated! Controller: $scope.date=[ {ID:1,Date:'2016-11-12'}, {ID:2,Date:'2016-11-15'}, ...

Is it possible to pass in two separate variables to an ng directive in Angular?

I've been working on developing a password validation directive, but I've encountered a few challenges. You can find the code in this jsfiddle link One issue is that when I enter information into one input box, it automatically updates the othe ...

Is there a way to stop a specific route in Express from continuing further execution without completing its function?

In my post route, I need to ensure that the user has provided all the necessary data in the body. To achieve this, I have added an if block to check for errors. router.post("/", (req, res) => { if(req.body.age < 24) { res.send("You are too you ...

Updating dropdown selection with JavaScript

I have a dropdown select menu with two options. I am using JavaScript to retrieve the selected value from the drop-down menu and display it in a text area. Here is my code: $(document).ready(function () { $('#pdSev').change(function () { ...

The age-old debate: Deciding between JavaScript's touchend and

Currently delving into some JavaScript UI work, focusing on optimizing touch events like 'touchend' for smoother interactions on touch-enabled devices. Nonetheless, encountering a few perplexing logical dilemmas... A common practice I've no ...

Loop through a JSON object

I am looking to iterate through a JSON object called transactionByFop. Here is the HTML code: <div ng-show="searchController.orderCAT.results.length" ng-repeat="(key,obj) in searchController.orderCAT.results track by $index"> <dl sty ...

Guide on Adding a Map to a List in JavaScript

Currently, I am trying to extract data from a form and add it as a map to my list. However, an error message is displayed: Cannot read property 'url' of undefined express = require("express"); app = express(); var bodyParser = require("body- ...

The most effective method for displaying a timestamp in the user's specific timezone using Node.JS

My application logs user events and stores timestamps as dates in Mongo, which are then converted to JS Date objects with timezone information based on the server's timezone. Although I am using moment.js to format the dates, the issue arises because ...

How about displaying the Ajax response as an image?

I'm working on a script that pulls an image link, which seems to be functioning correctly. However, I am struggling with how to display the link as an image. Can someone please assist me with this? <script src="//ajax.googleapis.com/ajax/li ...

Using Javascript's document.write function to modify the content of a PHP page

Here is a Javascript function that capitalizes the first letter of a string: function capitalizeFL(string) { return string.charAt(0).toUpperCase() + string.slice(1); } In a file named statuswindow.php, there are PHP scripts that use this function to ...

Vertical scrollbar in iframe unexpectedly appears immediately after the submit button is pressed

I have designed a contact form that is displayed in an iframe within an overlay div. I have carefully adjusted the dimensions of this div to ensure that there are no scrollbars visible when the form initially appears. However, after filling out the form an ...