Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing Volume Mesh UV
#1
I change UV scale by this piece of code:

Code:
_buildVolumeMesh.MaterialSetttings[0].UVScale.y = _buildVolumeMesh.InVolume.GetData<CGVolume>().Length / 200

But it doesn't take place. What should I do ?
Right now it happens in runtime. What should I do if I want to happens in edit time ? Just by putting [ExecuteInEditMode] or I should do anything else ?

Edit: I think it is done by calling Refresh of BuildVolumeMesh module. Am I right ?

Edit 2: I try to have same texture size on all of my splines but I can't achieve it by changing Y UV, I assume 1 amount of Y UV for, for instance 200 length and then by dividing spline length by 200 and assigning to Y UV Scale, I can't achieve what I want.
The code:
Code:
_buildVolumeMesh.MaterialSetttings[0].UVScale.y = _buildVolumeMesh.InVolume.GetData<CGVolume>().Length / 200
What should I do ?

https://gyazo.com/306799228567b33b5c48039a319c4857
Reply
#2
Hi,

about that line of code, it depends on what other code executes before that. You are using _buildVolumeMesh.InVolume.GetData<CGVolume>().Length, so make sure the generator is initialized and up to date before using that data (see Initialize and Refresh methods in the CurvyGenerator class)

Make sure Length returns the right value by using Debug.Log. Compute the value manually and set it in the generator manually to see if the desired result is there. If so, see if the automatically computed value is the same than the manually computed one. By following those steps you should be able to find what went wrong

Yes, [ExecuteInEditMode] is to make that code execute in edit mode
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(02-20-2020, 01:25 AM)_Aka_ Wrote: Hi,

about that line of code, it depends on what other code executes before that. You are using _buildVolumeMesh.InVolume.GetData<CGVolume>().Length, so make sure the generator is initialized and up to date before using that data (see Initialize and Refresh methods in the CurvyGenerator class)

Make sure Length returns the right value by using Debug.Log. Compute the value manually and set it in the generator manually to see if the desired result is there. If so, see if the automatically computed value is the same than the manually computed one. By following those steps you should be able to find what went wrong

Yes, [ExecuteInEditMode] is to make that code execute in edit mode

I check them all. The length is correct. Just not sure if I do the right job or not!
How to change UV to have same result in all of the splines ?

Edit: The problem was because of Keep Aspect. I don't know how it works but I disabled it and calculated UV Scale of Y.
Reply
#4
Hey there,

I use this script on Build Volume Mesh of generator:

Code:
public class VolumeMeshController : MonoBehaviour
{
   [SerializeField] private float _referenceUVScaleY = 0.07f;
   [SerializeField] private bool _flip = false;
}

Code:
[CustomEditor(typeof(VolumeMeshController))]
public class VolumeMeshControllerEditor : UnityEditor.Editor
{
   private SerializedProperty _referenceUVScaleYProperty;
   private SerializedProperty _flipProperty;
   private Transform _transform;
   private BuildVolumeMesh _buildVolumeMesh;

   void OnEnable()
   {
       _transform = (target as VolumeMeshController).transform;

       _buildVolumeMesh = _transform.GetComponent<BuildVolumeMesh>();

       GetSerialiezedProperties();
   }

   public override void OnInspectorGUI()
   {
       base.OnInspectorGUI();

       // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
       serializedObject.Update();

       UpdateUV();

       // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
       serializedObject.ApplyModifiedProperties();
   }

   private void GetSerialiezedProperties()
   {
       _referenceUVScaleYProperty = serializedObject.FindProperty("_referenceUVScaleY");
       _flipProperty = serializedObject.FindProperty("_flip");
   }

   private void UpdateUVScale()
   {
       int flip = !_flipProperty.boolValue ? 1 : -1;
       CGVolume data = _buildVolumeMesh.InVolume.GetData<CGVolume>();
       _buildVolumeMesh.MaterialSetttings[0].UVScale.x = flip;
       _buildVolumeMesh.MaterialSetttings[0].UVScale.y = data.Length * flip * _referenceUVScaleYProperty.floatValue;
       _buildVolumeMesh.Refresh();
   }
}

The problem is although I put that Refresh at the end of UpdateUVScale but still after changing _referenceUVScaleY value, there is no effect on the texture in the scene but in its generator the values are changed. (As you noticed I want this functionality in edit mode)

Where the problem is ? Any idea ?
Reply
#5
Have you found the solution? Have you tried calling _buildVolumeMesh.Generator.Refresh() instead?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
(03-08-2020, 01:55 PM)_Aka_ Wrote: Have you found the solution? Have you tried calling _buildVolumeMesh.Generator.Refresh() instead?

Not yet.
_buildVolumeMesh.Generator.Refresh() doesn't work either.
Reply
#7
Anything ?
Reply
#8
After testing, I found that you will need, in the case of modifying the material settings via API, to mark the module Dirty by hand. Most properties changes do dirty the module automatically. When a module is not dirty, calling refresh on it will do nothing.
So just add _buildVolumeMesh.Dirty = true;
before
_buildVolumeMesh.Refresh();

have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
(03-10-2020, 10:37 PM)_Aka_ Wrote: After testing, I found that you will need, in the case of modifying the material settings via API, to mark the module Dirty by hand. Most properties changes do dirty the module automatically. When a module is not dirty, calling refresh on it will do nothing.
So just add _buildVolumeMesh.Dirty = true;
before
_buildVolumeMesh.Refresh();

have a nice day

Thanks. It solved my problem.

How can I find spline by BuildVolumeMesh component ? I need CurvySpline OnRefresh event.
Reply
#10
Only Input Spline Path module (and its Shape equivalent) have a reference to a spline. It transforms it to a Path (in code CGPath), and that is what is used in the remaining of the generator.
Each CG module has a reference to its input and output modules, see Input and Output lists
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adjust radius of generated mesh via script? Shackman 1 3 03-26-2024, 01:12 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
Question Volume Spots inter group distance Sacryn 1 3 02-27-2024, 04:08 PM
Last Post: _Aka_
  Not seeing mesh extended after following YT PaulM 1 3 02-02-2024, 12:01 PM
Last Post: _Aka_

Forum Jump: