|
@@ -17,6 +17,7 @@
|
|
|
*/
|
|
|
|
|
|
#include "../la_5.h"
|
|
|
+#include "nanovg.h"
|
|
|
|
|
|
extern LA MAIN;
|
|
|
extern struct _tnsMain *T;
|
|
@@ -106,7 +107,8 @@ void la_AssignObjectSelectIDRecursive(tnsObject* root, MSelectData* sd){
|
|
|
if(o->ChildObjects.pFirst){ la_AssignObjectSelectIDRecursive(o,sd); }
|
|
|
}
|
|
|
}
|
|
|
-void la_PopulateSelectDataObjects(MSelectData* sd, tnsObject* root, tnsCamera* camera){
|
|
|
+void la_PopulateSelectDataObjects(MSelectData* sd, tnsObject* root, laCanvasExtra* e){
|
|
|
+ tnsCamera* camera=e->ViewingCamera;
|
|
|
arrEnsureLength(&sd->RefsV,0,&sd->maxV,sizeof(tnsObject*));
|
|
|
sd->nextV++; // starting from 1;
|
|
|
la_AssignObjectSelectIDRecursive(root, sd);
|
|
@@ -115,13 +117,20 @@ void la_PopulateSelectDataObjects(MSelectData* sd, tnsObject* root, tnsCamera* c
|
|
|
tnsEnableShaderv(T->SelectionShader);
|
|
|
glDisableVertexAttribArray(T->SelectionShader->iColor); glVertexAttrib4f(T->SelectionShader->iColor,0,0,0,0);
|
|
|
tnsViewportWithScissor(0,0,w,h);tnsResetViewMatrix();tnsResetModelMatrix();tnsResetProjectionMatrix();
|
|
|
- tnsApplyCameraView(w,h,camera);
|
|
|
- glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
|
|
- glEnable(GL_DEPTH_TEST);
|
|
|
+
|
|
|
+ NVGcontext* vg=MAIN.CurrentWindow->nvg;
|
|
|
+ la3DObjectDrawExtra de={0}; de.W=w; de.H=h;
|
|
|
+ tnsMatrix44d mview,mproj; tnsRootObject* ro=root;
|
|
|
+ if(ro && ro->Is2D){ la_SetCanvasOrtho(e,w,h); }
|
|
|
+ else{ tnsApplyCameraView(w, h, camera, mview,mproj); tnsMultiply44d(de.mViewProj,mproj,mview); de.Is3D=1; }
|
|
|
+ la_BeginNVG(vg,e,w,h,ro->Is2D);
|
|
|
+
|
|
|
+ glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST);
|
|
|
tnsInvalidateEvaluation(root); tnsSetObjectTreeEvaluationArgs(root,root->Active,1,1); tnsEvaluateObjectTree(root,0,0);
|
|
|
- tnsDrawObjectTree(root,TNS_EVAL_LAYER_SELECTION,0,0);
|
|
|
- glDisable(GL_DEPTH_TEST);
|
|
|
- tnsEnableShaderv(T->immShader);
|
|
|
+ tnsDrawObjectTree(root,TNS_EVAL_LAYER_SELECTION,&de,0);
|
|
|
+ glDisable(GL_DEPTH_TEST);
|
|
|
+
|
|
|
+ nvgEndFrame(vg); tnsRestoreFromNanoVG(); tnsEnableShaderv(T->immShader);
|
|
|
}
|
|
|
void la_PopulateSelectVerts(MSelectData* sd, tnsMeshObject* mo){
|
|
|
arrEnsureLength(&sd->RefsV,0,&sd->maxV,sizeof(tnsMVert*));
|
|
@@ -150,7 +159,7 @@ void la_PopulateSelectDataPrimitives(MSelectData* sd, tnsMeshObject* mo, tnsCame
|
|
|
tnsUnbindTexture(); tnsUniformUseTexture(T->immShader,0,0); tnsUseMultiplyColor(0);
|
|
|
tnsEnableShaderv(T->SelectionShader);
|
|
|
tnsViewportWithScissor(0,0,w,h);tnsResetViewMatrix();tnsResetModelMatrix();tnsResetProjectionMatrix();
|
|
|
- tnsApplyCameraView(w,h,camera);
|
|
|
+ tnsApplyCameraView(w,h,camera,0,0);
|
|
|
glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
|
|
tnsPushMatrix(); tnsApplyModelMatrix(mo->Base.GlobalTransform);glEnable(GL_DEPTH_TEST);
|
|
|
if(!SelectThrough){
|
|
@@ -337,7 +346,7 @@ int OPINV_Select(laOperator *a, laEvent *e){
|
|
|
tnsInvalidateMeshBatch(mo);
|
|
|
laNotifyUsers("tns.world"); laRecordAndPush(0,"tns.world","Mesh selection",TNS_HINT_GEOMETRY);
|
|
|
}else{
|
|
|
- la_PopulateSelectDataObjects(sd,root,ex->ViewingCamera);
|
|
|
+ la_PopulateSelectDataObjects(sd,root,ex);
|
|
|
if(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"), "box")){
|
|
|
MSelectExtra* se=memAcquire(sizeof(MSelectExtra));
|
|
|
ex->OnX=e->x; ex->OnX=e->y;
|
|
@@ -435,9 +444,10 @@ STRUCTURE(MTransformData){
|
|
|
real DeltaVal, UserDeltaVal;
|
|
|
laStringEdit* Entry; int UseUserDelta;
|
|
|
int CanvasDeltaMode;
|
|
|
+ int Is2D; real zoomx,zoomy;
|
|
|
};
|
|
|
|
|
|
-MTransformData* la_InitTransformData(int w, int h, tnsCamera* c, int CanvasDeltaMode){
|
|
|
+MTransformData* la_InitTransformData(int w, int h, tnsCamera* c, int CanvasDeltaMode, int Is2D,real zoomx,real zoomy){
|
|
|
MTransformData* td=memAcquireSimple(sizeof(MTransformData));
|
|
|
tnsVector4d pu={0,1,0,0}, pr={1,0,0,0}, pf={0,0,1};
|
|
|
tnsGetCameraMovingDeltas(c,w,h,1,0,pr); pr[2]=0; pr[3]=0;
|
|
@@ -446,10 +456,10 @@ MTransformData* la_InitTransformData(int w, int h, tnsCamera* c, int CanvasDelta
|
|
|
tnsApplyRotation43d(td->Up,inv,pu);
|
|
|
tnsApplyRotation43d(td->Right,inv,pr);
|
|
|
tnsApplyRotation43d(td->Foward,inv,pf);
|
|
|
-
|
|
|
tnsGetCameraViewProjection(td->ViewProjection, w,h,c);
|
|
|
td->c=c; td->w=w; td->h=h; td->CanvasDeltaMode=CanvasDeltaMode;
|
|
|
strBeginEdit(&td->Entry, "");
|
|
|
+ td->Is2D=Is2D; td->zoomx=zoomx; td->zoomy=zoomy;
|
|
|
return td;
|
|
|
}
|
|
|
void la_GetTransformInitialScale(MTransformData* td, laUiItem* ui, int x, int y){ td->Initial=tnsDistIdv2(x-ui->L,y-ui->U,td->CenterX,td->CenterY); }
|
|
@@ -502,16 +512,21 @@ int la_PopulateTransformVerticies(MTransformData* td, tnsMeshObject* mo){
|
|
|
return any;
|
|
|
}
|
|
|
void la_ApplyTranslation(MTransformData* td, int x, int y){
|
|
|
- tnsMatrix44d trans; tnsVector3d deltay,delta; tnsVector3d gp;
|
|
|
- tnsVectorMulti3d(delta, td->Right, x); tnsVectorMulti3d(deltay, td->Up, y); tnsVectorAccum3d(delta, deltay);
|
|
|
- tnsVector3d use_delta={LA_COLOR3(delta)}; real len;
|
|
|
- if(td->LockAxis[0]||td->LockAxis[1]||td->LockAxis[2]){ len=tnsLength3d(delta); }
|
|
|
- if(td->LockAxis[0]>0){ use_delta[1]=use_delta[2]=0; real l=fabs(use_delta[0]); use_delta[0]=l?use_delta[0]*len/l:1e-7; }
|
|
|
- if(td->LockAxis[1]>0){ use_delta[0]=use_delta[2]=0; real l=fabs(use_delta[1]); use_delta[1]=l?use_delta[1]*len/l:1e-7; }
|
|
|
- if(td->LockAxis[2]>0){ use_delta[0]=use_delta[1]=0; real l=fabs(use_delta[2]); use_delta[2]=l?use_delta[2]*len/l:1e-7; }
|
|
|
- if(td->LockAxis[0]<0){ use_delta[0]=0; real l=tnsLength3d(use_delta); tnsVectorMultiSelf3d(use_delta, l?len/l*len/l:0); }
|
|
|
- if(td->LockAxis[1]<0){ use_delta[1]=0; real l=tnsLength3d(use_delta); tnsVectorMultiSelf3d(use_delta, l?len/l*len/l:0); }
|
|
|
- if(td->LockAxis[2]<0){ use_delta[2]=0; real l=tnsLength3d(use_delta); tnsVectorMultiSelf3d(use_delta, l?len/l*len/l:0); }
|
|
|
+ tnsMatrix44d trans; tnsVector3d deltay,delta; tnsVector3d gp; tnsVector3d use_delta;
|
|
|
+ if(td->Is2D){
|
|
|
+ use_delta[0]=x*td->zoomx; use_delta[1]=-y*td->zoomy; use_delta[2]=0;
|
|
|
+ if(td->LockAxis[0]){ use_delta[1]=0; } if(td->LockAxis[1]){ use_delta[0]=0; }
|
|
|
+ }else{
|
|
|
+ tnsVectorMulti3d(delta, td->Right, x); tnsVectorMulti3d(deltay, td->Up, y); tnsVectorAccum3d(delta, deltay);
|
|
|
+ tnsVectorSet3v(use_delta,delta); real len;
|
|
|
+ if(td->LockAxis[0]||td->LockAxis[1]||td->LockAxis[2]){ len=tnsLength3d(delta); }
|
|
|
+ if(td->LockAxis[0]>0){ use_delta[1]=use_delta[2]=0; real l=fabs(use_delta[0]); use_delta[0]=l?use_delta[0]*len/l:1e-7; }
|
|
|
+ if(td->LockAxis[1]>0){ use_delta[0]=use_delta[2]=0; real l=fabs(use_delta[1]); use_delta[1]=l?use_delta[1]*len/l:1e-7; }
|
|
|
+ if(td->LockAxis[2]>0){ use_delta[0]=use_delta[1]=0; real l=fabs(use_delta[2]); use_delta[2]=l?use_delta[2]*len/l:1e-7; }
|
|
|
+ if(td->LockAxis[0]<0){ use_delta[0]=0; real l=tnsLength3d(use_delta); tnsVectorMultiSelf3d(use_delta, l?len/l*len/l:0); }
|
|
|
+ if(td->LockAxis[1]<0){ use_delta[1]=0; real l=tnsLength3d(use_delta); tnsVectorMultiSelf3d(use_delta, l?len/l*len/l:0); }
|
|
|
+ if(td->LockAxis[2]<0){ use_delta[2]=0; real l=tnsLength3d(use_delta); tnsVectorMultiSelf3d(use_delta, l?len/l*len/l:0); }
|
|
|
+ }
|
|
|
td->DeltaVal=tnsLength3d(use_delta);
|
|
|
if(td->UseUserDelta){
|
|
|
tnsVectorMultiSelf3d(use_delta,1/tnsLength3d(use_delta)*td->UserDeltaVal);
|
|
@@ -576,11 +591,12 @@ void la_ApplyScale(MTransformData* td, int uix, int uiy){
|
|
|
void la_ApplyRotation(MTransformData* td, int uix, int uiy){
|
|
|
tnsMatrix44d trans; real a=atan2(uiy-td->CenterY,uix-td->CenterX);
|
|
|
real angle=a-td->Initial; tnsVector3d gp; tnsVector3d LimFoward={0}; real* use_forward=td->Foward;
|
|
|
+ if(td->Is2D){ use_forward=LimFoward; LimFoward[2]=1; }
|
|
|
if(td->LockAxis[0]||td->LockAxis[1]||td->LockAxis[2]){ use_forward=LimFoward; }
|
|
|
- if(td->LockAxis[0]){ LimFoward[0]=1; }
|
|
|
- if(td->LockAxis[1]){ LimFoward[1]=1; }
|
|
|
+ if(td->LockAxis[0]){ LimFoward[0]=1; LimFoward[2]=0; }
|
|
|
+ if(td->LockAxis[1]){ LimFoward[1]=1; LimFoward[2]=0; }
|
|
|
if(td->LockAxis[2]){ LimFoward[2]=1; }
|
|
|
- if(td->UseUserDelta) angle=rad(td->UserDeltaVal); td->DeltaVal=deg(angle);
|
|
|
+ if(td->UseUserDelta) angle=rad(td->UserDeltaVal); td->DeltaVal=deg(angle);
|
|
|
if(!td->mo){
|
|
|
for(int i=0;i<td->next;i++){
|
|
|
MTOrigObject* to=arrElement(td->Originals, i, sizeof(MTOrigObject)); memcpy(to->o->GlobalTransform, to->Global,sizeof(tnsMatrix44d));
|
|
@@ -667,9 +683,11 @@ int la_InitTransform(laOperator* a, laEvent* e, int mode, int restore_type, int
|
|
|
if(!a->This || !a->This->EndInstance){ return 0; }
|
|
|
laCanvasExtra* ex=a->This->EndInstance; tnsCamera*c=ex->ViewingCamera; laUiItem* ui=ex->ParentUi;
|
|
|
tnsObject*root=ui?ui->PP.EndInstance:0; if(!root) return 0;
|
|
|
- tnsMeshObject* mo=root->Active;
|
|
|
+ tnsMeshObject* mo=root->Active; tnsRootObject*ro=root;
|
|
|
|
|
|
- MTransformData* td=la_InitTransformData(ex->OffScr->pColor[0]->Width, ex->OffScr->pColor[0]->Height, c, ex->DeltaMode);
|
|
|
+ MTransformData* td=la_InitTransformData(
|
|
|
+ ex->OffScr->pColor[0]->Width, ex->OffScr->pColor[0]->Height, c, ex->DeltaMode,
|
|
|
+ ro->Is2D, ex->ZoomX,ex->ZoomY);
|
|
|
a->CustomData = td;
|
|
|
td->mode=mode;
|
|
|
td->root=root;
|
|
@@ -1255,7 +1273,7 @@ int OPINV_Add(laOperator *a, laEvent *e){
|
|
|
elif(strSame(str,"INSTANCER")){ tnsDeselectAllObjects(root);
|
|
|
no=tnsCreateInstancer(root, "Instancer",0,0,0); no->Flags|=TNS_OBJECT_FLAGS_SELECTED; memAssignRef(root,&root->Active,no); ran=1; }
|
|
|
elif(strSame(str,"SQUARE")){ tnsDeselectAllObjects(root);
|
|
|
- no=tnsCreateShapeSquare(root, "Square",0,0,0,10); no->Flags|=TNS_OBJECT_FLAGS_SELECTED; memAssignRef(root,&root->Active,no); ran=1; }
|
|
|
+ no=tnsCreateShapeSquare(root, "Square",0,0,0,1); no->Flags|=TNS_OBJECT_FLAGS_SELECTED; memAssignRef(root,&root->Active,no); ran=1; }
|
|
|
else{ laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e); return LA_RUNNING; }
|
|
|
if(ran){ laRecordAndPush(0,"tns.world","Add object",TNS_HINT_GEOMETRY); laNotifyUsers("tns.world"); }
|
|
|
}elif(mo->Base.Type==TNS_OBJECT_MESH && mo->Mode!=TNS_MESH_EDIT_MODE){ ad->Context=LA_ADD_CTX_MESH;
|