Is it possible to sketch basic 2D shapes onto 3D models?

Is the technique called projective texture mapping? Are there any existing library methods that can be used to project basic 2D shapes, such as lines, onto a texture?

I found an example in threejs that seems similar to what I'm looking for. I attempted to substitute the decal texture (decalMaterial) with

THREE.LineBasicMaterial

However, instead of lines, I ended up with squares.

Answer №1

Adding a line to a 3D texture presents an interesting challenge. Are you looking to create a decal on your model or actually paint onto the texture? There are alternative methods for applying decals that may be more suitable, but let's explore painting onto the texture. While I have experience with Unity in this aspect, WebGL presents its own set of limitations which I am not as familiar with. The process involves using a program similar to Substance Painter or ZBrush that allows you to paint directly onto 3D models. It is advisable to approach this non-destructively at runtime by working on a separate render texture and then combining it with the final model texture for rendering.

To achieve this, you must first render your model into texture space by outputting the UV coordinates of the model in your vertex shader.

Having recently focused on hlsl and Cg coding, my knowledge of glsl is somewhat outdated. Consider the following code snippet as pseudocode:

//Vertex Shader
in vec4 position;
in vec2 uv;

out vec4 fworldPos;
out vec2 fuv;
uniform mat4 transform;

void main()
{
   gl_Position = vec4(uv.x*2.0-1.0, uv.y*2.0-1.0, 0.0, 1.0);
   fuv = uv;
   fworldPos = transform * position;
}

In the pixel shader, implement collision detection with your brush to determine if the world position falls within the brush area. In a recent project, we utilized raycasts for the brush to follow the model surface seamlessly. This method results in an initial rough brush stroke, requiring fine-tuning parameters such as falloff strength and radius to achieve desired effects - similar to settings found in traditional 3D painting software.

You can use various shapes like planes, boxes, spheres, and lines for painting. The key is to check if the world position aligns with the brush shape. Different shaders will be necessary depending on the type of brush being used.

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

req.next does not exist as a function [END]

I am currently working on developing a website and I have encountered an issue in the dashboard stage. The error message TypeError: req.next is not a function keeps appearing, particularly when trying to create a subpage for the dashboard. I am utilizing t ...

Changing the format of a numerical value to include commas for every 1000 increment

I'm trying to find a way to format numbers in a specific manner, such as changing 1234567 into 1,234,567. However, I've run into some issues when attempting to use the currency pipe of TypeScript. It adds USD or $ in front of the number, which i ...

Best method for extracting object values from an array in Javascript using loops?

Recently Updated: Complete values of respons: "{"versions":[ { "name":"Windows 8.1 with Update 3 (build 9600)", "version_id":"11" }, { "name":"Windows 7 SP1 (build 7601)", "version_id":"9" }, { "name": ...

Is there a way to initiate the server only after webpack has finished bundling all of the bundles

"scripts": { "start": "node server.js", "build": "webpack" }, Is there a way to execute both npm run build and npm start with a single command? "scripts": { "start": " ...

The processing-js library threw a Reference Error indicating that the Navigator could not be found

I am looking to utilize processingJS as an npm package in a nodeJS server for deployment on MS Azure. I am using VS15 and encountering difficulties referencing it: var pjs = require('processing-js'); var http = require('http'), fs = r ...

Setting the selected option of a select form element dynamically in Vue 3

Is there a way to dynamically set the selected option in Vue 3 when the data value doesn't match any available option value? Situation: If Florida (FL) is the stored state value and the country changes from United States (US) to Canada (CA), the Sta ...

How can I effectively monitor and track modifications to a document's properties in MongoDB?

I'm wondering how to effectively track the values of a document in MongoDB. This involves a MongoDB Database with a Node and Express backend. For example, let's say there is a document within the Patients collection: { "_id": "4k2lK49938d ...

AngularJS constants are values that can be accessed and

Is it feasible to inject one constant into another constant using AngularJS? For example: var app = angular.module('myApp'); app.constant('foo', { message: "Hello" } ); app.constant('bar', ['foo', function(foo) ...

The functionality of a generated button has been compromised

My goal is to create a webshop that doesn't rely on MySQL or any database, but instead reads items from JSON and stores them in LocalStorage. However, I've encountered an issue where the functionality of buttons gets lost after using AJAX to gene ...

Designing an interactive region using HTML, CSS, and JavaScript

I recently created this code with some assistance: When I tried to format the code, it all ended up on one line and looked unreadable. To view the code properly, please visit this link: http://jsfiddle.net/QFF4x/ <div style="border:1px solid black;" ...

Adjusting the placement in Draw2D

I'm a newcomer to this library and I'm struggling to figure out how to properly size and position the canvas. If anyone could provide guidance on the best way to do this, I would greatly appreciate it. $(window).load(function () { // se ...

Difficulty with formatting decimal points in JavaScript

I seem to be having an issue with decimal places in my code. Currently, it's showing the result as 123 123 12 but I actually need it to be displayed as 12 312 312. Is there anyone who can assist me with formatting this correctly? Here is the section ...

What is the correct way to incorporate scrollIntoView() using jQuery?

I'm trying to implement a jQuery function that will enable the last reply to scroll into view. This is my current code: function displayLastReply(replies){ replies.each(function() { if($(this).index() < nIniRep || afterReply){ $( ...

Arranging a collection of objects (Displaying information in a random sequence)

Here is a summary of the data returned in a shortened version: var array = [{ "response": { "itineraries":[ { "price": { "totalPricePerPassenger":"104" ...

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): https://i.sstatic.net/xcqaT.png EDIT: The layout on large scre ...

The setAttribute method does not function with getElementByClass()

Can someone please help me understand why this code is not working for me: document.getElementByClass('home1').setAttribute('style', 'background-image:url(img/red_menu.PNG);'); I have confirmed that I do indeed have an eleme ...

Symfony2 compresses CSS and JS files to improve performance

Currently, I am attempting to execute php app/console assetic:dump in order to test my production environment. While my css file gets generated successfully, the js file does not. The following error message is displayed : C:\wamp\www\p ...

The 'propTypes' property is not found on the 'typeof TextInput' type declaration

Trying my hand at creating a react-native component using Typescript for the first time, but I ran into an issue on line 51: Property 'propTypes' does not exist on type 'typeof TextInput Couldn't find any helpful information on similar ...

Is it possible to deselect a checkbox in a Datagrid Material-ui by clicking a button?

I have set up a grid in Datagrid Material-UI with a checkbox. I am trying to figure out how to uncheck the checkbox by clicking a reset button after it has been checked. For example: https://i.sstatic.net/Za1E6.png This is the DataGrid code I currently ...

Having trouble altering the error response code in feathers.js

I'm utilizing an authentication service for login validation. In this case, I am looking to change the Unauthorized (401) response code to 200 while keeping the message the same. The authentication service setup is as follows: app.service('auth ...