123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- /*
- * LaGUI: A graphical application framework.
- * Copyright (C) 2022 Wu Yiming
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "../la_5.h"
- extern LA MAIN;
- extern struct _tnsMain *T;
- laBaseNodeType TNS_IDN_TRANSFORM;
- laBaseNodeType TNS_IDN_MAKE_TRANSFORM;
- laPropContainer* TNS_PC_IDN_TRANSFORM;
- laPropContainer* TNS_PC_IDN_MAKE_TRANSFORM;
- void IDN_TransformInit(tnsTransformNode* n, int NoCreate){
- if(NoCreate){return;}
- n->Mat=laCreateInSocket("MAT",0); strSafeSet(&n->Base.Name,"Transform");
- }
- void IDN_TransformDestroy(tnsTransformNode* n){
- laDestroyInSocket(n->Mat); strSafeDestroy(&n->Base.Name);
- }
- int IDN_TransformVisit(tnsTransformNode* n, laListHandle* l){
- if(LA_SRC_AND_PARENT(n->Mat)){ laBaseNode*bn=n->Mat->Source->Parent; LA_VISIT_NODE(bn); }
- n->Base.Eval=LA_DAG_FLAG_PERM;
- lstAppendPointer(l, n);
- return LA_DAG_FLAG_PERM;
- }
- int IDN_TransformEval(tnsTransformNode* n){
- if(!n->Target) return 0;
- if((!n->Mat->Source) || (n->Mat->Source->DataType!=(LA_PROP_FLOAT|LA_PROP_ARRAY)) || (n->Mat->Source->ArrLen!=16)){
- tnsLoadIdentity44d(&n->Target->DeltaTransform); tnsSelfMatrixChanged(n->Target, 1);
- }else{
- memcpy(n->Target->DeltaTransform, n->Mat->Source->Data, sizeof(tnsMatrix44d)); tnsSelfMatrixChanged(n->Target, 1);
- }
- laNotifyInstanceUsers(n->Target);
- return 1;
- }
- void tnsui_TransformNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
- laColumn* c=laFirstColumn(uil); tnsTransformNode*n=This->EndInstance;
- LA_BASE_NODE_HEADER(uil,c,This);
- laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
- laUiItem* b=laBeginRow(uil,cl,0,0);
- laShowNodeSocket(uil,cl,This,"mat",0)->Flags|=LA_UI_SOCKET_LABEL_E;
- laEndRow(uil,b);
- laShowItem(uil,cr,This,"target");
- }
- void IDN_MakeTransformInit(tnsMakeTransformNode* n, int NoCreate){
- if(NoCreate){return;}
- n->Out=laCreateOutSocket(n,"MAT",0); strSafeSet(&n->Base.Name,"Make Transform");
- n->Loc=laCreateInSocket("LOC",0);
- n->Rot=laCreateInSocket("ROT",0); n->Angle=laCreateInSocket("ANGLE",0); n->UseRot[2]=1;
- n->Sca=laCreateInSocket("SCALE",0); n->UseSca=1;
- }
- void IDN_MakeTransformDestroy(tnsMakeTransformNode* n){
- laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name);
- laDestroyInSocket(n->Loc);
- laDestroyInSocket(n->Rot); laDestroyInSocket(n->Angle);
- laDestroyInSocket(n->Sca);
- }
- int IDN_MakeTransformVisit(tnsMakeTransformNode* n, laListHandle* l){
- LA_GUARD_THIS_NODE(n);
- if(LA_SRC_AND_PARENT(n->Loc)){ laBaseNode*bn=n->Loc->Source->Parent; LA_VISIT_NODE(bn); }
- if(LA_SRC_AND_PARENT(n->Rot)){ laBaseNode*bn=n->Rot->Source->Parent; LA_VISIT_NODE(bn); }
- if(LA_SRC_AND_PARENT(n->Sca)){ laBaseNode*bn=n->Sca->Source->Parent; LA_VISIT_NODE(bn); }
- if(LA_SRC_AND_PARENT(n->Angle)){ laBaseNode*bn=n->Angle->Source->Parent; LA_VISIT_NODE(bn); }
- n->Base.Eval=LA_DAG_FLAG_PERM; lstAppendPointer(l, n);
- return LA_DAG_FLAG_PERM;
- }
- int IDN_MakeTransformEval(tnsMakeTransformNode* n){
- tnsMatrix44d mm,mt,mr,ms; real* UseT,*UseR,*UseA,*UseS; tnsVector3d nr;
- if(LA_SRC_AND_PARENT(n->Loc) && n->Loc->Source->ArrLen>=3 && n->Loc->Source->DataType==LA_PROP_FLOAT|LA_PROP_ARRAY){ UseT=n->Loc->Source->Data; }else{ UseT=n->UseLoc; }
- if(LA_SRC_AND_PARENT(n->Rot) && n->Rot->Source->ArrLen>=3 && n->Rot->Source->DataType==LA_PROP_FLOAT|LA_PROP_ARRAY){ UseR=n->Rot->Source->Data; }else{ UseR=n->UseRot; }
- if(LA_SRC_AND_PARENT(n->Angle) && n->Angle->Source->DataType&LA_PROP_FLOAT){ UseA=n->Angle->Source->Data; }else{ UseA=&n->UseAngle; }
- if(LA_SRC_AND_PARENT(n->Sca) && n->Sca->Source->DataType&LA_PROP_FLOAT){ UseS=n->Sca->Source->Data; }else{ UseS=&n->UseSca; }
- tnsMakeTranslationMatrix44d(mt,LA_COLOR3(UseT));
- tnsNormalize3d(nr, UseR); tnsMakeRotationMatrix44d(mr,*UseA, LA_COLOR3(nr));
- tnsMakeScaleMatrix44d(ms,*UseS,*UseS,*UseS);
- tnsMultiply44d(mm,mt,mr); tnsMultiply44d(n->Mat,mm,ms);
- n->Out->ArrLen=16; n->Out->Data=n->Mat; n->Out->DataType=LA_PROP_FLOAT|LA_PROP_ARRAY;
- return 1;
- }
- void tnsui_MakeTransformNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
- laColumn* c=laFirstColumn(uil); tnsMakeTransformNode*n=This->EndInstance;
- laUiItem* b2, *rui;
- LA_BASE_NODE_HEADER(uil,c,This);
- laUiItem* b=laBeginRow(uil,c,0,0);
- laShowNodeSocket(uil,c,This,"loc",0)->Flags|=LA_UI_SOCKET_LABEL_E; b2=laOnConditionThat(uil,c,laNot(laPropExpression(This,"loc.source")));{
- laShowItem(uil,c,This,"use_loc")->Expand=1;
- }laEndCondition(uil,b2);
- laEndRow(uil,b);
- b=laBeginRow(uil,c,0,0);
- laShowNodeSocket(uil,c,This,"rot",0)->Flags|=LA_UI_SOCKET_LABEL_E; b2=laOnConditionThat(uil,c,laNot(laPropExpression(This,"rot.source")));{
- laShowItem(uil,c,This,"use_rot")->Expand=1;
- }laEndCondition(uil,b2);
- laEndRow(uil,b);
- b=laBeginRow(uil,c,0,0);
- laShowNodeSocket(uil,c,This,"angle",0)->Flags|=LA_UI_SOCKET_LABEL_E; b2=laOnConditionThat(uil,c,laNot(laPropExpression(This,"angle.source")));{
- laShowItem(uil,c,This,"use_angle")->Expand=1;
- }laEndCondition(uil,b2);
- laEndRow(uil,b);
- b=laBeginRow(uil,c,0,0);
- laShowNodeSocket(uil,c,This,"sca",0)->Flags|=LA_UI_SOCKET_LABEL_E; b2=laOnConditionThat(uil,c,laNot(laPropExpression(This,"sca.source")));{
- laShowItem(uil,c,This,"use_sca")->Expand=1;
- }laEndCondition(uil,b2);
- laEndRow(uil,b);
- b=laBeginRow(uil,c,0,0);
- laShowSeparator(uil,c)->Expand=1;;
- laShowNodeSocket(uil,c,This,"out",0)->Flags|=LA_UI_SOCKET_LABEL_W;
- laEndRow(uil,b);
- }
- int OPINV_AddDriverPage(laOperator* a, laEvent *e){
- laRackPage* dp=memAcquire(sizeof(laRackPage));
- strSafeSet(&dp->Name,"New Page");
- lstAppendItem(&MAIN.Drivers->Pages, dp); MAIN.Drivers->CurrentPage=dp; dp->RackType=LA_RACK_TYPE_DRIVER;
- laNotifyUsers("la.drivers.pages"); laRecordAndPush(0,"la.drivers","Add page", 0);
- return LA_FINISHED;
- }
- int OPINV_RebuildDrivers(laOperator* a, laEvent *e){
- laDriverRequestRebuild();
- return LA_FINISHED;
- }
- tnsObject* tnsget_FirstObject(void* unused, void* unused2){
- return T->World.AllObjects.pFirst;
- }
- void tns_RegisterNodes(){
- laPropContainer *pc; laProp *p;
- laOperatorType *at;
- laEnumProp *ep;
- laCreateOperatorType("LA_add_driver_page", "New Page", "Add a driver page", 0,0,0,OPINV_AddDriverPage,0,'+',0);
- laCreateOperatorType("LA_driver_rebuild", "Rebuild Drivers", "Rebuild drivers for evaluation",0,0,0,OPINV_RebuildDrivers,0,L'⭮',0);
- pc=laAddPropertyContainer("tns_transform_node", "Transform", "Transform objects",0,tnsui_TransformNode,sizeof(tnsTransformNode),lapost_Node,0,1);
- TNS_PC_IDN_TRANSFORM=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
- laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
- laAddSubGroup(pc,"mat", "Mat","Input matrix","la_in_socket",0,0,0,offsetof(tnsTransformNode,Mat),0,0,0,0,0,0,0,LA_UDF_SINGLE);
- laAddSubGroup(pc,"target", "Target","Target object","tns_object",0,LA_WIDGET_COLLECTION_SELECTOR,laui_IdentifierOnly,offsetof(tnsTransformNode,Target),tnsget_FirstObject,0,laget_ListNext,0,0,0,0,LA_UDF_REFER);
-
- pc=laAddPropertyContainer("tns_make_transform_node", "Make Transform", "Make Transform matrix",0,tnsui_MakeTransformNode,sizeof(tnsMakeTransformNode),lapost_Node,0,1);
- TNS_PC_IDN_MAKE_TRANSFORM=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
- laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
- laAddSubGroup(pc,"out", "Out","Output matrix","la_out_socket",0,0,0,offsetof(tnsMakeTransformNode,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
- laAddSubGroup(pc,"loc", "Location","Location","la_in_socket",0,0,0,offsetof(tnsMakeTransformNode,Loc),0,0,0,0,0,0,0,LA_UDF_SINGLE);
- laAddSubGroup(pc,"rot", "Rotation","Rotation","la_in_socket",0,0,0,offsetof(tnsMakeTransformNode,Rot),0,0,0,0,0,0,0,LA_UDF_SINGLE);
- laAddSubGroup(pc,"sca", "Scale","Scale","la_in_socket",0,0,0,offsetof(tnsMakeTransformNode,Sca),0,0,0,0,0,0,0,LA_UDF_SINGLE);
- laAddSubGroup(pc,"angle", "Angle","Rotation Angle","la_in_socket",0,0,0,offsetof(tnsMakeTransformNode,Angle),0,0,0,0,0,0,0,LA_UDF_SINGLE);
- laAddFloatProperty(pc,"use_loc", "Location", "Use Location",0,"X,Y,Z",0,0,0,0.05,0,0,offsetof(tnsMakeTransformNode, UseLoc),0,0,3,0,0,0,0,0,0,0,0);
- laAddFloatProperty(pc,"use_rot", "Rotation", "Use Rotation",0,"X,Y,Z",0,0,0,0.05,0,0,offsetof(tnsMakeTransformNode, UseRot),0,0,3,0,0,0,0,0,0,0,0);
- laAddFloatProperty(pc,"use_sca", "Scale", "Use Scale",0,0,0,0,0,0.05,0,0,offsetof(tnsMakeTransformNode, UseSca),0,0,0,0,0,0,0,0,0,0,0);
- laAddFloatProperty(pc,"use_angle", "Angle", "Use Angle",0,0,0,0,0,0.05,0,0,offsetof(tnsMakeTransformNode, UseAngle),0,0,0,0,0,0,0,0,0,0,0);
-
- LA_IDN_REGISTER("Transform",0,TNS_IDN_TRANSFORM,TNS_PC_IDN_TRANSFORM, IDN_TransformInit, IDN_TransformDestroy, IDN_TransformVisit, IDN_TransformEval, tnsTransformNode);
- LA_IDN_REGISTER("Make Transform",0,TNS_IDN_MAKE_TRANSFORM,TNS_PC_IDN_MAKE_TRANSFORM, IDN_MakeTransformInit, IDN_MakeTransformDestroy, IDN_MakeTransformVisit, IDN_MakeTransformEval, tnsMakeTransformNode);
- LA_NODE_CATEGORY_DRIVER=laAddNodeCategory("Driver",0,LA_RACK_TYPE_DRIVER);
- laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_MATH, &TNS_IDN_MAKE_TRANSFORM,0);
- laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_DRIVER, &TNS_IDN_TRANSFORM,0);
- }
- void laDriverRequestRebuild(){ MAIN.Drivers->NeedRebuild=1; }
- void laDriverRequestEval(){ MAIN.Drivers->NeedEval=1; }
- int la_RunDrivers(){
- MAIN.Drivers->NeedEval = 0;
- for(laListItemPointer*lip=MAIN.Drivers->Eval.pFirst;lip;lip=lip->pNext){
- laBaseNode* n=lip->p; if(!n->InitDone){ n->Type->Init(n,1); n->InitDone=1; } n->Type->Eval(n);
- }
- return 1;
- }
- int la_RebuildDriverEval(){
- MAIN.Drivers->NeedRebuild = 0;
- while(lstPopPointer(&MAIN.Drivers->Eval));
- laListHandle pending={0};
- for(laRackPage* dp=MAIN.Drivers->Pages.pFirst;dp;dp=dp->Item.pNext){
- for(laNodeRack* ir=dp->Racks.pFirst;ir;ir=ir->Item.pNext){
- for(laBaseNode*bn=ir->Nodes.pFirst;bn;bn=bn->Item.pNext){ if(!bn->InitDone){ bn->Type->Init(bn,1); bn->InitDone=1; } lstAppendPointer(&pending,bn); bn->Eval=0; }
- }
- }
- laBaseNode*n;int result=LA_DAG_FLAG_PERM; laListItemPointer*NextLip;
- for(laListItemPointer*lip=pending.pFirst;lip;lip=NextLip){ n=lip->p; NextLip=lip->pNext;
- if(n->Eval&LA_DAG_FLAG_PERM) continue;
- result=n->Type->Visit(n,&MAIN.Drivers->Eval); if(result==LA_DAG_FLAG_ERR){ while(lstPopPointer(&pending)); break; }
- }
- if(result==LA_DAG_FLAG_ERR){ while(lstPopPointer(&MAIN.Drivers->Eval)); return LA_DAG_FLAG_ERR; }
- return LA_DAG_FLAG_PERM;
- }
|