11-17-2022, 10:11 AM
(11-16-2022, 07:00 PM)tairoark Wrote:(11-16-2022, 10:35 AM)_Aka_ Wrote: I think you can solve it doing the following:
listening on the OnRefresh event, in it update the UV offset then call yourGenerator.Refresh(). That way the UVs are updated before the next frame rendering
That is what I'm doing:
Code:var bvm = gen.GetModule<BuildVolumeMesh>( "Track Vol Mesh", true );
bvm.SetMaterial( 0, material );
bvm.MaterialSetttings[ 0 ].KeepAspect = CGKeepAspectMode.ScaleV;
var cm = gen.GetModule<CreateMesh>( "Track Create Mesh", true );
cm.OnRefresh.AddListenerOnce( _ => {
var prevSeg = seg.Spline.GetPreviousControlPoint( seg );
float savedForNextSegUVOffsetY;
if (prevSeg == null) {
savedForNextSegUVOffsetY = bvm.MaterialSetttings[ 0 ].UVOffset.y + bvm.groupsByMatID[ 0 ].AspectCorrectionV;
}
else {
savedForNextSegUVOffsetY = prevSeg.EndBias + bvm.groupsByMatID[ 0 ].AspectCorrectionV; // EndBias will hold the accumulated Offset to the end of it's segment
if (prevSeg.GetMetadata<TrackMetadata>().Geo.materialName == geo.materialName
&& Math.Abs( bvm.MaterialSetttings[ 0 ].UVOffset.y - prevSeg.EndBias ) > 0.001f) {
bvm.MaterialSetttings[ 0 ].UVOffset.y = prevSeg.EndBias;
}
}
if (Math.Abs( savedForNextSegUVOffsetY - seg.EndBias ) > 0.001f) {
seg.EndBias = savedForNextSegUVOffsetY;
}
gen.AutoRefresh = true;
} );
gen.Refresh( true );
Where does this code belong?
Have you tried calling gen.Refresh inside the event listener, in place of gen.AutoRefresh = true? I advise to listen on the OnRefresh event of the generator and not the module, so that you don't trigger a Refresh operation in the middle of the execution of a previous Refresh. When the generator's OnRefresh is called, you know that the refreshing is over.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.