*/}}
Browse Source

Material animation basics

YimingWu 1 year ago
parent
commit
c194c1dc8a
6 changed files with 43 additions and 39 deletions
  1. 1 1
      la_animation.c
  2. 1 2
      la_tns.h
  3. 2 2
      la_tns_kernel.c
  4. 16 1
      la_tns_shape.c
  5. 1 1
      resources/la_operators.c
  6. 22 32
      resources/la_properties.c

+ 1 - 1
la_animation.c

@@ -214,12 +214,12 @@ void laAnimationRemoveChannel(laAction* aa, laActionChannel* ac){
 }
 void laAnimationRemoveAction(laAction* aa){
     while(aa->Channels.pFirst){ laAnimationRemoveChannel(aa,aa->Channels.pFirst); }
+    if(!aa->HolderContainer || !aa->HolderInstance){ return; }
     strSafeDestroy(&aa->Name);
     if(aa=MAIN.Animation->CurrentAction){
         if(aa->Item.pNext){ memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa->Item.pNext); }
         else{ memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa->Item.pPrev); }
     }
-    if(!aa->HolderContainer || !aa->HolderInstance){ goto action_remove_clean; }
     laSubProp* paa=la_PropLookup(&aa->HolderContainer->Props,"__actions__"); if(!paa){ goto action_remove_clean; }
     laListHandle* al=((uint8_t*)aa->HolderInstance)+paa->ListHandleOffset;
     lstRemoveItem(al,aa);

+ 1 - 2
la_tns.h

@@ -591,7 +591,6 @@ STRUCTURE(tnsMaterial){
     tnsVector2d GradientCenter;
     tnsVector2d GradientSize;
     real GradientBoxR,GradientBoxF;
-    NVGpaint Paint;
 };
 
 STRUCTURE(tnsRootObject){
@@ -1288,7 +1287,7 @@ tnsMaterialSlot* tnsNewMaterialSlot(tnsObject* o);
 void tnsRemoveMaterialSlot(tnsObject* o, tnsMaterialSlot* ms);
 void tnsAssignMaterialSlot(tnsObject* o, tnsMaterialSlot* ms);
 
-void tns_RefreshMaterial2D(tnsMaterial* m);
+NVGpaint tns_GetMaterial2D(tnsMaterial* m);
 void tnsRefreshMaterialLibraries();
 void tnsEnsureMaterialShader(tnsMaterial* mat, int Refresh);
 

+ 2 - 2
la_tns_kernel.c

@@ -3484,7 +3484,7 @@ tnsObject *tnsCreateRootObject(char *name, int Use2D){
 
     o->Base.Drivers=memAcquire(sizeof(laRackPageCollection));
     o->Is2D=Use2D;
-    
+
     laAnimationUpdateHolderList();
 
     return o;
@@ -4193,7 +4193,7 @@ tnsMaterial *tnsCreateMaterial(char *Name){
     m = memAcquireHyper(sizeof(tnsMaterial));
     strSafeSet(&m->Name, Name); tnsVectorSet4(m->Color,0.8,0.8,0.8,1); tnsVectorSet4(m->Color2,0.8,0.8,0.8,1);
     m->Page=memAcquire(sizeof(laRackPage));
-    lstAppendItem(&T->World->Materials, m); tns_RefreshMaterial2D(m);
+    lstAppendItem(&T->World->Materials, m);
     return m;
 }
 tnsMaterial *tnsFindMaterial(char *name){

+ 16 - 1
la_tns_shape.c

@@ -239,6 +239,21 @@ void tnsInitShapeSquare(tnsShapeObject* so, real size){
     tnsShapeSetClosed(s,1,0); tnsShapeRefreshIndex(so);
 }
 
+NVGpaint tns_GetMaterial2D(tnsMaterial* m){
+    NVGcontext* vg=MAIN.CurrentWindow->nvg;
+    if(m->GradientMode==TNS_GRADIENT_MODE_LINEAR){
+        return nvgLinearGradient(vg,m->GradientCenter[0],m->GradientCenter[1],m->GradientSize[0],m->GradientSize[1],
+            nvgRGBAf(LA_COLOR4(m->Color)),nvgRGBAf(LA_COLOR4(m->Color2)));
+    }elif(m->GradientMode==TNS_GRADIENT_MODE_BOX){
+        return nvgBoxGradient(vg,m->GradientCenter[0],m->GradientCenter[1],m->GradientSize[0],m->GradientSize[1],
+            m->GradientBoxR,m->GradientBoxF,nvgRGBAf(LA_COLOR4(m->Color)),nvgRGBAf(LA_COLOR4(m->Color2)));
+    }elif(m->GradientMode==TNS_GRADIENT_MODE_RADIAL){
+        return nvgRadialGradient(vg,m->GradientCenter[0],m->GradientCenter[1],m->GradientSize[0],m->GradientSize[1],
+            nvgRGBAf(LA_COLOR4(m->Color)),nvgRGBAf(LA_COLOR4(m->Color2)));
+    }
+    NVGpaint p={0}; return p;
+}
+
 void tns_DrawShape(tnsShape* s, tnsMaterial* mat, real* override_color, int DrawEdit, real PointScale){
     if(!s->Points.pFirst) return; int HasSelection=0; int closed=(s->flags&TNS_SHAPE_CLOSED);
     NVGcontext* vg=MAIN.CurrentWindow->nvg;
@@ -278,7 +293,7 @@ void tns_DrawShape(tnsShape* s, tnsMaterial* mat, real* override_color, int Draw
         nvgPathWinding(vg,(s->flags&TNS_SHAPE_HOLE)?NVG_HOLE:NVG_SOLID);
         if(!(s->flags&TNS_SHAPE_HOLE)){
             if((!override_color) && mat && mat->GradientMode){
-                nvgFillPaint(vg,mat->Paint);
+                nvgFillPaint(vg,tns_GetMaterial2D(mat));
             }else{
                 nvgFillColor(vg, override_color?nvgRGBAf(LA_COLOR4(override_color)):(mat?nvgRGBAf(LA_COLOR4(mat->Color)):nvgRGBAf(0.8,0.8,0.8,1)));
             }

+ 1 - 1
resources/la_operators.c

@@ -897,7 +897,7 @@ int OPINV_PropInsertKey(laOperator *a, laEvent *e){
         char msg[1024]; char _id[128]="unknown container",*id=_id,_idc[128]="unknown object",*idc=_idc;
         laTryGetInstanceIdentifier(aa->HolderInstance,aa->HolderContainer,_id,&id);
         laTryGetInstanceIdentifier(a->This->LastPs->UseInstance,a->This->LastPs->p->Container,_idc,&idc);
-        sprintf(msg,"Can't insert key frame into current action.\n\"%s\" doesn't come from an action under \"%s\".",idc,id);
+        sprintf(msg,"Can't insert key frame into current action.\n\"%s\" doesn't belong to \"%s\".",idc,id);
         laEnableMessagePanel(a,0,"Error",msg,e->x,e->y,100,e);
     }
     return LA_FINISHED;

+ 22 - 32
resources/la_properties.c

@@ -812,7 +812,7 @@ void tnspost_World(tnsWorld *w){
     laAnimationUpdateHolderList();
 }
 void tnspost_Material(tnsMaterial *m){
-    tns_RefreshMaterial2D(m);
+    tns_GetMaterial2D(m);
     //if(m->AsLibrary){ tnsRefreshMaterialLibraries(); return; }
     //tnsEnsureMaterialShader(m,1);
 }
@@ -905,27 +905,14 @@ void tns_InvalidateMeshWithMaterial(tnsMaterial* m){
     }
 }
 void tnsset_MaterialColor(tnsMaterial* m, real* c){
-    tnsVectorCopy4d(c,m->Color); tns_InvalidateMeshWithMaterial(m); tns_RefreshMaterial2D(m); laNotifyUsers("tns.world");
-}
-void tns_RefreshMaterial2D(tnsMaterial* m){
-    NVGcontext* vg=MAIN.CurrentWindow->nvg;
-    if(m->GradientMode==TNS_GRADIENT_MODE_LINEAR){
-        m->Paint=nvgLinearGradient(vg,m->GradientCenter[0],m->GradientCenter[1],m->GradientSize[0],m->GradientSize[1],
-            nvgRGBAf(LA_COLOR4(m->Color)),nvgRGBAf(LA_COLOR4(m->Color2)));
-    }elif(m->GradientMode==TNS_GRADIENT_MODE_BOX){
-        m->Paint=nvgBoxGradient(vg,m->GradientCenter[0],m->GradientCenter[1],m->GradientSize[0],m->GradientSize[1],
-            m->GradientBoxR,m->GradientBoxF,nvgRGBAf(LA_COLOR4(m->Color)),nvgRGBAf(LA_COLOR4(m->Color2)));
-    }elif(m->GradientMode==TNS_GRADIENT_MODE_RADIAL){
-        m->Paint=nvgRadialGradient(vg,m->GradientCenter[0],m->GradientCenter[1],m->GradientSize[0],m->GradientSize[1],
-            nvgRGBAf(LA_COLOR4(m->Color)),nvgRGBAf(LA_COLOR4(m->Color2)));
-    }
-}
-void tnsset_MaterialColor2(tnsMaterial* m, real* c){ tnsVectorCopy4d(c,m->Color2); tns_RefreshMaterial2D(m); laNotifyUsers("tns.world"); }
-void tnsset_MaterialGradientMode(tnsMaterial* m, int Mode){ m->GradientMode=Mode; tns_RefreshMaterial2D(m); laNotifyUsers("tns.world"); }
-void tnsset_MaterialGradientCenter(tnsMaterial* m, real* c){ tnsVectorCopy2d(c,m->GradientCenter); tns_RefreshMaterial2D(m); laNotifyUsers("tns.world"); }
-void tnsset_MaterialGradientSize(tnsMaterial* m, real* c){ tnsVectorCopy2d(c,m->GradientSize); tns_RefreshMaterial2D(m); laNotifyUsers("tns.world"); }
-void tnsset_MaterialGradientF(tnsMaterial* m, real c){ m->GradientBoxF=c; tns_RefreshMaterial2D(m); laNotifyUsers("tns.world"); }
-void tnsset_MaterialGradientR(tnsMaterial* m, real c){ m->GradientBoxR=c; tns_RefreshMaterial2D(m); laNotifyUsers("tns.world"); }
+    tnsVectorCopy4d(c,m->Color); tns_InvalidateMeshWithMaterial(m); laNotifyUsers("tns.world");
+}
+void tnsset_MaterialColor2(tnsMaterial* m, real* c){ tnsVectorCopy4d(c,m->Color2);  laNotifyUsers("tns.world"); }
+void tnsset_MaterialGradientMode(tnsMaterial* m, int Mode){ m->GradientMode=Mode; laNotifyUsers("tns.world"); }
+void tnsset_MaterialGradientCenter(tnsMaterial* m, real* c){ tnsVectorCopy2d(c,m->GradientCenter); laNotifyUsers("tns.world"); }
+void tnsset_MaterialGradientSize(tnsMaterial* m, real* c){ tnsVectorCopy2d(c,m->GradientSize); laNotifyUsers("tns.world"); }
+void tnsset_MaterialGradientF(tnsMaterial* m, real c){ m->GradientBoxF=c; laNotifyUsers("tns.world"); }
+void tnsset_MaterialGradientR(tnsMaterial* m, real c){ m->GradientBoxR=c; laNotifyUsers("tns.world"); }
 void tnsget_MaterialSlotname(tnsMaterialSlot* ms, char *result, char** here){
     if(!ms){ strcpy(result,"?"); return; }
     if(ms->Material&&ms->Material->Name&&ms->Material->Name->Ptr){
@@ -1004,9 +991,12 @@ void laget_ActionContainer(laAction* aa, char* str, char** here){ *here=aa->Hold
 void laread_ActionContainer(laAction* aa, char* str){ aa->HolderContainer=la_ContainerLookup(str); }
 
 int laaction_VerifyRootObject(void* Parent, laPropContainer* ParentType, void* Child, laPropContainer* ChildType){
-    if(ParentType!=ChildType) return 0;
-    if(ParentType!=TNS_PC_OBJECT_GENERIC) return 0;
-    tnsObject*o=Child; if(o==Parent || o->InRoot==Parent) return 1;
+    if(ParentType!=TNS_PC_OBJECT_ROOT) return 0;
+    if (ChildType==TNS_PC_OBJECT_GENERIC||ChildType==TNS_PC_OBJECT_CAMERA||ChildType==TNS_OBJECT_SHAPE||
+        ChildType==TNS_PC_OBJECT_INSTANCER||ChildType==TNS_PC_OBJECT_LIGHT||ChildType==TNS_OBJECT_MESH){
+        tnsObject*o=Child; if(o==Parent || o->InRoot==Parent) return 1;
+    }
+    if (ChildType==TNS_PC_MATERIAL){ return 1; }
     return 0;
 }
 
@@ -1161,8 +1151,8 @@ void la_RegisterTNSProps(){
     p = laAddPropertyContainer("tns_material", "Material" "Object material", 0,0,0,sizeof(tnsMaterial),tnspost_Material,0,2);{
         TNS_PC_MATERIAL=p;
         laAddStringProperty(p, "name", "Material Name", "The name ff the material", 0,0,0,0,1, offsetof(tnsMaterial, Name), 0,0,0,0,LA_AS_IDENTIFIER);
-        laAddFloatProperty(p, "color", "Color", "Base color of the material", LA_WIDGET_FLOAT_COLOR, "R,G,B,A", 0,1,0,0.025, 1, 0,offsetof(tnsMaterial, Color), 0,0,4, 0,0,0,0,tnsset_MaterialColor,0,0,0);
-        laAddFloatProperty(p, "color2", "Color 2", "Gradient end color of the material", LA_WIDGET_FLOAT_COLOR, "R,G,B,A", 0,1,0,0.025, 1, 0,offsetof(tnsMaterial, Color2), 0,0,4, 0,0,0,0,tnsset_MaterialColor2,0,0,0);
+        laAddFloatProperty(p, "color", "Color", "Base color of the material", LA_WIDGET_FLOAT_COLOR, "R,G,B,A", 0,1,0,0.025, 1, 0,offsetof(tnsMaterial, Color), 0,0,4, 0,0,0,0,tnsset_MaterialColor,0,0,LA_PROP_KEYABLE);
+        laAddFloatProperty(p, "color2", "Color 2", "Gradient end color of the material", LA_WIDGET_FLOAT_COLOR, "R,G,B,A", 0,1,0,0.025, 1, 0,offsetof(tnsMaterial, Color2), 0,0,4, 0,0,0,0,tnsset_MaterialColor2,0,0,LA_PROP_KEYABLE);
         ep = laAddEnumProperty(p, "colorful", "Colorful", "Use colorful display", 0,0,0,0,0,offsetof(tnsMaterial, Colorful), 0,0,0,0,0,0,0,0,0,0);{
             laAddEnumItemAs(ep, "NONE", "None", "Display materials normally",0,0);
             laAddEnumItemAs(ep, "COLORFUL", "Colorful", "Display material with colorful halftone",1,0);
@@ -1176,10 +1166,10 @@ void la_RegisterTNSProps(){
         laAddEnumItemAs(ep,"LINEAR","Linear","Do linear gradient",TNS_GRADIENT_MODE_LINEAR,0);
         laAddEnumItemAs(ep,"BOX","Box","Do box gradient",TNS_GRADIENT_MODE_BOX,0);
         laAddEnumItemAs(ep,"RADIAL","Radial","Do radial gradient",TNS_GRADIENT_MODE_RADIAL,0);
-        laAddFloatProperty(p,"gradient_center","Gradient Center","Starting point of the gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientCenter),0,0,2,0,0,0,0,tnsset_MaterialGradientCenter,0,0,0);
-        laAddFloatProperty(p,"gradient_size","Gradient Size","Size of the gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientSize),0,0,2,0,0,0,0,tnsset_MaterialGradientSize,0,0,0);
-        laAddFloatProperty(p,"gradient_box_r","Corner","Corner radius of the box gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientBoxR),0,tnsset_MaterialGradientR,0,0,0,0,0,0,0,0,0);
-        laAddFloatProperty(p,"gradient_box_f","Feather","Feather distance of the box gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientBoxF),0,tnsset_MaterialGradientF,0,0,0,0,0,0,0,0,0);
+        laAddFloatProperty(p,"gradient_center","Gradient Center","Starting point of the gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientCenter),0,0,2,0,0,0,0,tnsset_MaterialGradientCenter,0,0,LA_PROP_KEYABLE);
+        laAddFloatProperty(p,"gradient_size","Gradient Size","Size of the gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientSize),0,0,2,0,0,0,0,tnsset_MaterialGradientSize,0,0,LA_PROP_KEYABLE);
+        laAddFloatProperty(p,"gradient_box_r","Corner","Corner radius of the box gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientBoxR),0,tnsset_MaterialGradientR,0,0,0,0,0,0,0,0,LA_PROP_KEYABLE);
+        laAddFloatProperty(p,"gradient_box_f","Feather","Feather distance of the box gradient",0,0,0,0,0,0,0,0,offsetof(tnsMaterial,GradientBoxF),0,tnsset_MaterialGradientF,0,0,0,0,0,0,0,0,LA_PROP_KEYABLE);
         laAddSubGroup(p, "shader_page", "Shader Page", "Shader page of this material","la_rack_page",0,0,0,offsetof(tnsMaterial,Page),0,0,0,0,0,0,0,LA_UDF_SINGLE|LA_HIDE_IN_SAVE);
         laAddOperatorProperty(p,"refresh","Refresh","Refresh material shader","M_refresh_material_shader",L'🗘',0);
         laAddOperatorProperty(p,"remove","Remove","Remove this material","M_remove_material",L'🗴',0);
@@ -1195,7 +1185,6 @@ void la_RegisterTNSProps(){
     }
 
     p = laAddPropertyContainer("tns_object", "Object", "3D Object Item", 0,tnsui_BaseObjectProperties,sizeof(tnsObject), tnspost_Object, 0,2);{
-        laContainerAnimationFunctions(p,laaction_VerifyRootObject);
         TNS_PC_OBJECT_GENERIC=p;
         laAddStringProperty(p, "name", "Object Name", "The Name Of The Object", 0,0,0,0,1, offsetof(tnsObject, Name), 0,0,0,0,LA_AS_IDENTIFIER);
         laAddIntProperty(p,"flags","Flags","Flags",0,0,0,0,0,0,0,0,offsetof(tnsObject,Flags),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
@@ -1243,6 +1232,7 @@ void la_RegisterTNSProps(){
     }
     p = laAddPropertyContainer("tns_root_object", "Root Object", "Root object", 0, tnsui_RootObjectProperties,sizeof(tnsRootObject), 0,0,2);{
         laPropContainerExtraFunctions(p,0,0,tnstouched_Object,tnspropagate_Object,tnsui_RootObjectMenuUi);
+        laContainerAnimationFunctions(p,laaction_VerifyRootObject); 
         TNS_PC_OBJECT_ROOT=p;
         laAddStringProperty(p, "name", "Object Name", "The Name Of The Object", 0,0,0,0,1, offsetof(tnsObject, Name), 0,0,0,0,LA_AS_IDENTIFIER);
         laAddSubGroup(p, "base", "Base", "Object base", "tns_object",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);