Posts: 46
Threads: 13
Joined: Jan 2020
02-19-2020, 10:42 AM
(This post was last modified: 02-19-2020, 04:32 PM by ATHellboy.)
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
Posts: 2,114
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
02-20-2020, 05:43 AM
(This post was last modified: 02-20-2020, 11:42 AM by ATHellboy.)
(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.
Posts: 46
Threads: 13
Joined: Jan 2020
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 ?
Posts: 2,114
Threads: 92
Joined: Jun 2017
Have you found the solution? Have you tried calling _buildVolumeMesh.Generator.Refresh() instead?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
(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.
Posts: 46
Threads: 13
Joined: Jan 2020
Posts: 2,114
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
(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.
Posts: 2,114
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.