Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: logiquefloue on October 25, 2013, 02:55:59 AM

Title: Set Uvs Coordinates[SOLVED]
Post by: logiquefloue on October 25, 2013, 02:55:59 AM
Hello,

You can do this with PlayMaker? :
Set all Uvs vector with coordinates (x1, y1) of the game object to new coordinates (x2, y2).

Thank you for your help
Title: Re: Set Uvs Coordinates
Post by: parallel on October 25, 2013, 04:32:15 AM
Yes, you can drag the material (or any other component) on to your fsm state 'sheet' and you are offered to get/ set properties for whatever the component has exposed, with materials you can get/set the x and y of uv's for example.
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 25, 2013, 04:46:32 AM
Thank you for the answer.

But I can not find in the properties "UV coordinates" of the game object. for more information, I want to move the coordinates of the mesh of the object and not the material (texture)

thank you
Title: Re: Set Uvs Coordinates
Post by: parallel on October 25, 2013, 04:57:30 AM
Sorry misunderstood that. No UV's are not available for editing straight out of the box AFAIK. There are some UV editing packs on asset store but don't know if they offer variable movement.
Title: Re: Set Uvs Coordinates
Post by: parallel on October 25, 2013, 05:04:29 AM
Maybe there's another way to get what you want without tweaking UV's ?
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 25, 2013, 05:15:31 AM
I made this script that works (I started in the program), if anyone can transform into action PlayMaker to enjoy everyone ...

Code: [Select]
#pragma strict
 
public var theCube : Transform;

function Start ()
{
 var x1 : float = 0.0;
 var y1 : float = 0.0;
 var x2 : float = 1.0;
 var y2 : float = 1.0;

     if (theCube == null)
        theCube = this.transform;
 
    var theMesh : Mesh = theCube.GetComponent(MeshFilter).mesh as Mesh;
  var UVs : Vector2[] = new Vector2[theMesh.uv.Length];
    UVs = theMesh.uv;
   
 for (var i:int = 0; i < theMesh.vertices.length; i ++) {
 
 if (UVs[i] == Vector2 (x1,y1)){
       
  UVs[i] = Vector2 (x2, y2);
  }
 
 theMesh.uv = UVs;
             
 
  }
     
}

I try to animate the uv coordinates to simulate a rise in temperatures of an object. I made a texture dérgadée (from red to blue) and I want to move the uvs depending on the temperatures.
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 25, 2013, 06:03:01 AM
I use "mouse pick uv" to trace the UV coordinates.
When I change the uv coordinates via script, "mouse pick uv" does not give me the new coordinates, but it still shows me the original details! (Uv map made in Blender)

Any idea?
Title: Re: Set Uvs Coordinates
Post by: escpodgames on October 25, 2013, 07:09:19 AM
http://hutonggames.com/playmakerforum/index.php?topic=2285.msg10058#msg10058
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 25, 2013, 08:26:48 AM
Thank you, but the action moves all uv mesh. True?
I'm looking to control a uv mesh in an individual way (with a selection of initial coordinates)
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 26, 2013, 03:18:33 AM
Hi,

 Simply adapt the script you made with that custom action, Have you tried?

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 26, 2013, 05:33:30 AM
Hi,

 Simply adapt the script you made with that custom action, Have you tried?

bye,

 Jean

Hello Jean

I tried but my programming skills are minimal. but I'm still at same point. must share all frame works because the variable is calculated by equations

thank you
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 26, 2013, 09:08:21 AM
Hi,

 Ok, I think the current behavior that you created will cause massive performance hit if you stat using it on big meshes. You would be better storing references of UV indexes against temperatures and only adjust the one you need to change, in your case, this means that ALL uvs are scanned for ALL changes, that 99% do not apply.

But anyway here's a custom action for this. If you are having trouble making it work, let me know.

Bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 27, 2013, 12:13:22 PM
Hello John and thank you for action ...

The filter is not working.
1 / When I chose a base value, all coordinates are set (0.0)! not to the target value
2 / When no base value is selected, all coordinates are set to target value (this function very well)

You're right, it is not necessary that this function every frame.
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 28, 2013, 01:21:50 AM
Hi,

 Could you provide a repro scene? I am not sure what's wrong here.

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 28, 2013, 04:48:34 AM
Hello jean,

I do not put A scene in this post a scene! Here are some screen printing.

When one of the values ​​(base) of the filter is set, all UVS targets are set (0.0)
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 28, 2013, 05:16:48 AM
Hi,

 It works here, I think you are simply not properly setting the base values, so it doesn't match any uvs.

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 28, 2013, 06:11:30 AM
Very strange!

I pay attention to basic values ​​(here uv base values ​​of the cube)

Another strange thing , the values ​​displayed by UV "mouse pick uv" remains that of the original mesh and does not change when I move the uvs while the texture changes color!
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 28, 2013, 08:45:08 AM
Hi,

 your uv values showned for the cube are wrong, uv ranges from 0.0 to 1.0, so what script are you using the get these values?

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 28, 2013, 11:09:20 AM
This is an imported cube Blender, the script told me exactly the same values ​​as in Blender.

Here is the script

Code: [Select]
#pragma strict
 
public var theCube : Transform;
private var theUVs : String = "";

function Start ()
{
    if (theCube == null)
        theCube = this.transform;
 
    var theMesh : Mesh = theCube.GetComponent(MeshFilter).mesh as Mesh;
     
    theUVs = theUVs + "(" + theMesh.uv.length.ToString() + ") :";
     
    for (var i:int = 0; i < theMesh.vertices.length; i ++) {
       
        theUVs = theUVs + "  " + i + "=" + theMesh.uv[i].ToString();
       
    }
}
 
function OnGUI ()
{
    GUI.Label( Rect( 10, Screen.height * 0.25, Screen.width - 20, Screen.height * 0.25), "UVs " + theUVs );
 
}

Having said that, with the following script, I can move my UVs ... but when I use "mouse select uv'' to the new coordinates, it does not work, I always start UV coordinates, have you any idea? Merci
Code: [Select]
#pragma strict
 
public var theCube : Transform;

function MoveUV_1 ( UVf : float)
{
     if (theCube == null)
        theCube = this.transform;
 
    var theMesh : Mesh = theCube.GetComponent(MeshFilter).mesh as Mesh;
  var UVs : Vector2[] = new Vector2[theMesh.uv.Length];
    UVs = theMesh.uv;
   
 for (var i:int = 0; i < theMesh.vertices.length; i ++) {
 
 if (UVs[i].x == 0.1){
       
  UVs[i] = Vector2 (0.1, UVf);
  }
 
 theMesh.uv = UVs;
             
 
  }
     
}
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 29, 2013, 02:19:19 AM
Hi,

 Then, pm me with this object and your scene if you can, cause it works ok with all the tests I carried over.

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 29, 2013, 03:55:19 AM
Hi,

Here the scene.

Reminder of malfunctions:

1 / If UV base is defined, the coordinates UV targets are defined in 0.0
2 / When I move the uv,  "Mouse Pick UV" always gives my old coordinates and not the news!
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 29, 2013, 05:10:30 AM
Hi,

 You need to package the scene, otherwise, I won't have the model and the texture.

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 29, 2013, 05:59:40 AM
sorry

Here the package
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 29, 2013, 08:22:25 AM
Hi,

 Ok, thanks, I could find the problem! Thanks for the scene, it helped me finding what exactly I was doing wrong in my tests. Can you redownload from the original post, ti should work fine now.

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 29, 2013, 10:05:47 AM
It works fine now, thanks  :)

The new coordinates are not displayed by "pick mouse UV" do you know why?
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 30, 2013, 01:27:06 AM
Hi,

 Maybe you should wait one frame, the mesh update cycle maybe not done yet.

bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 30, 2013, 03:30:07 AM
Hi Jean,

Uv pixel is set to "every frame". the strange thing is that the texture changes is OK (that means that the mesh is updated, right?) but we still have the old UV coordinates! The problem is visible on the package that I sent yesterday.

Thank you for your help.
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 30, 2013, 08:29:30 AM
Hi,

Try to put a mesh collider on the cube. A box collider will not work.


bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 30, 2013, 10:32:28 AM
Even with <Mesh collider> I do not have the new UV coordinates, and the old coordinates are displayed <Mouse Pick Uv>!
I think <Mouse Pick Uv> ignores changes to a mesh prefab in real time (execution)!

thank you
Title: Re: Set Uvs Coordinates
Post by: jeanfabre on October 31, 2013, 08:06:46 AM
Hi,

 Good catch, What happens is that editing a mesh can be done locally, or actually to the mesh on the asset folder ( the shared mesh), and then ALL components using this mesh will actually see the changes.

Redownload the action, it nows has options to "Affect shared mesh" when you set UV.

Bye,

 Jean
Title: Re: Set Uvs Coordinates
Post by: logiquefloue on October 31, 2013, 11:17:15 AM
Thank you very much Jean it works :). I learned a lot of things with you  ;)