webcam capture and use it as texture

hi my dear friends
i want to have a button which when clicked webcamera run and can shot and capture picture … then use that picture as texture of some of my models …
it means that i want to give my customers this ability to change the model texture via their mobile camera

is it possible ?
im very poor in programing … please explain it very clearly and simple
thanks alot

Hello,

For the usage of a webcam:
You have to use a WebCamTexture
Here is a ready to use script example.
You just have to copy the content of the example in a new C# script (the new script file have to be called “ExampleClass”).
Then attach the script on a plane or a quad you can create within Unity.

Now about your models texture shot thing, it’s easy, but it get way more complicated when you want your models to actually look good, depending on what you want to do.

To achieve that you just have to take a picture and apply the picture texture on the material you want.

Here is how.

1 Like

thank you very much dear fabian

i used this code and every thing is good …but i have some other questions … it takes a shot and saved it in drive C …
i want to publish my app for android and ios …
which path should i assign in this part of code that i can load it for texture !

private string _SavePath = "C:/WebcamSnaps/"; //Change the path here!

and how can i load that shot to my texture ?

thanks a lot

A few research in google and you will find what you need:

Saving path to use:

Load texture from disk:

it means that i have to write code like this:

private string _SavePath =Application.persistentDataPath;

i did that but i faced this error:

and for loading image it means that i have to use this code:

// Add this script to a GameObject. The Start() function fetches an
// image from the documentation site.  It is then applied as the
// texture on the GameObject.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {

    public string url = "https://docs.unity3d.com/uploads/Main/ShadowIntro.png";
  
    IEnumerator Start() {
  
        Texture2D tex;
        tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
        WWW www = new WWW(url);
        yield return www;
        www.LoadImageIntoTexture(tex);
        GetComponent<Renderer>().material.mainTexture = tex;
    }
}

and change the url to my path ?
something like this:

public string url = Application.persistentDataPath+"/0.png";
??

If you want to code you should learn the basis of programming before trying to do this or ask a programmer to do it for you against a proper exchange.

I have the feeling this thread will be a “I will do all the work for you”.

Good luck,

1 Like

thanks dear fabian

is there anyone else to help me more ?

You already got help: You were pointed to the tutorials!

Understand that this issue you’re asking us to solve is not the only one you’re going to run into. And you can’t just come ask someone to give you code each time something doesn’t work. Well, you can, but don’t expect people to do it.

If you want to be a game developer, you need to learn how to develop. That means either learning how to write code, or learning how to use a visual scripting tool (and accepting the things you sacrifice when you do so). It’s hard work, and no one can do it for you.

When you run into specific issues and show us that you’re working to solve it but need help, or you need further direction after you’ve followed the steps advised, we’ll be here and will be happy to assist.

3 Likes