12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676 |
- /*
- * LaGUI: A graphical application framework.
- * Copyright (C) 2022-2023 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;
- void la_ReadGLocation(tnsOffscreen* off, int x, int y,float* xyz0){
- glBindFramebuffer(GL_READ_FRAMEBUFFER, off->FboHandle);
- glReadBuffer(GL_COLOR_ATTACHMENT2); glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
- glReadPixels(x,y,1,1, GL_RGBA, GL_FLOAT, xyz0);
- }
- int OPINV_SetCursor(laOperator *a, laEvent *e){
- 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 || root->Type!=TNS_OBJECT_ROOT) return 0;
- float pos[4]; la_ReadGLocation(ex->OffScr, e->x-ui->L,ui->B-e->y,pos);
- if(pos[0]>-1e20){
- tnsVectorSet3v(root->GLocation,pos); laNotifyUsers("tns.world"); return LA_FINISHED_PASS;
- }else
- {
- if(!ex->ViewingCamera){ return LA_FINISHED_PASS; }
- real vv[4], gp[4]; tnsMatrix44d proj; tnsMatrix44d inv;
- real focus=ex->ViewingCamera->FocusDistance, _near=ex->ViewingCamera->ZMin, _far=ex->ViewingCamera->ZMax;
- tnsGetCameraViewProjection(proj,ui->R-ui->L,ui->B-ui->U,ex->ViewingCamera); tnsInverse44d(inv,proj);
- vv[0]=(real)(e->x-ui->L)/(real)(ui->R-ui->L)*2-1; vv[0]*=focus;
- vv[1]=(real)(ui->B-e->y)/(real)(ui->B-ui->U)*2-1; vv[1]*=focus;
- vv[2]=tnsGetRatiod(1/_near,1/_far,1/focus)*focus;
- vv[3]=focus;
- tnsApplyTransform44dTrue(gp, inv, vv);
- tnsVectorMultiSelf3d(gp,1/gp[3]);
- real vv0[3]={0,0,-1}, vv1[3], ray[3], p0[3]; real t; tnsMatrix44d inv2;
- tnsSelfTransformValueChanged(ex->ViewingCamera);tnsInverse44d(inv2,ex->ViewingCamera->Base.GlobalTransform);
- tnsApplyRotation43d(vv1,inv2,vv0);
- tnsVectorMulti3d(vv0,vv1,focus);
- tnsVectorAccum3d(vv0,ex->ViewingCamera->Base.GLocation);
- tnsVectorMinus3d(ray, gp, ex->ViewingCamera->Base.GLocation);
- tnsNormalizeSelf3d(ray);
- if(tnsIntersectPlaneRay(vv1,vv0,ex->ViewingCamera->Base.GLocation,ray,&t)){
- tnsVectorMultiSelf3d(ray,t); tnsVectorPlus3d(gp,ray,ex->ViewingCamera->Base.GLocation);
- }
- tnsVectorSet3v(root->GLocation,gp); laNotifyUsers("tns.world"); return LA_FINISHED_PASS;
- }
- return LA_FINISHED_PASS;
- }
- int OPCHK_ThereIsActiveObject(laPropPack *This, laStringSplitor *ss){
- if(!This || !This->EndInstance){ return 0; }
- laCanvasExtra* ex=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; if(!mo) return 0; return 1;
- }
- int OPINV_ToggleEdit(laOperator *a, laEvent *e){
- 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; if(!mo) return 0;
- if(mo->Base.Type!=TNS_OBJECT_MESH) return LA_CANCELED;
- if(mo->Mode==TNS_MESH_EDIT_MODE) tnsMeshLeaveEditMode(mo); else tnsMeshEnterEditMode(mo);
- laRecordInstanceDifferences(mo, "tns_mesh_object"); laPushDifferences("Toggle edit mode", TNS_HINT_GEOMETRY);
- laNotifyUsers("tns.world");
- return LA_FINISHED_PASS;
- }
- STRUCTURE(MSelectData){
- tnsOffscreen* FBO;
- tnsTexture* Color;
- void** RefsV; int nextV,maxV;
- void** RefsE; int nextE,maxE;
- };
- MSelectData* la_InitSelectData(int w, int h, tnsCamera* camera){
- MSelectData* sd=memAcquireSimple(sizeof(MSelectData));
- if (!sd->FBO || sd->FBO->pColor[0]->Height != h || sd->FBO->pColor[0]->Width != w){
- if (sd->FBO) tnsDelete2DOffscreen(sd->FBO);
- sd->FBO = tnsCreate2DOffscreen(GL_RGB, w, h, 0, 1, 0); sd->Color=sd->FBO->pColor[0];
- }
- tnsDrawToOffscreen(sd->FBO, 1, 0);
- return sd;
- }
- void la_AssignObjectSelectIDRecursive(tnsObject* root, MSelectData* sd){
- for(laListItemPointer*lip=root->ChildObjects.pFirst;lip;lip=lip->pNext){
- tnsObject* o=lip->p; if(!o) continue;
- arrEnsureLength(&sd->RefsV, sd->nextV, &sd->maxV, sizeof(tnsObject*));
- sd->RefsV[sd->nextV]=o; o->SelectID=sd->nextV; sd->nextV++;
- if(o->ChildObjects.pFirst){ la_AssignObjectSelectIDRecursive(o,sd); }
- }
- }
- void la_PopulateSelectDataObjects(MSelectData* sd, tnsObject* root, tnsCamera* camera){
- arrEnsureLength(&sd->RefsV,0,&sd->maxV,sizeof(tnsObject*));
- sd->nextV++; // starting from 1;
- la_AssignObjectSelectIDRecursive(root, sd);
- if(sd->nextV==1) return; int w=sd->Color->Width, h=sd->Color->Height;
- tnsUnbindTexture(); tnsUniformUseTexture(T->immShader,0,0); tnsUseMultiplyColor(0);
- 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);
- 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);
- }
- void la_PopulateSelectVerts(MSelectData* sd, tnsMeshObject* mo){
- arrEnsureLength(&sd->RefsV,0,&sd->maxV,sizeof(tnsMVert*));
- if(mo->Base.Type!=TNS_OBJECT_MESH||!mo->mv.pFirst){ return; }
- for(tnsMVert* v=mo->mv.pFirst;v;v=v->Item.pNext){
- arrEnsureLength(&sd->RefsV, v->i, &sd->maxV, sizeof(tnsObject*));
- sd->RefsV[v->i]=v; sd->nextV=TNS_MAX2(v->i, sd->nextV);
- }
- sd->nextV++;
- }
- void la_PopulateSelectEdges(MSelectData* sd, tnsMeshObject* mo){
- arrEnsureLength(&sd->RefsE,0,&sd->maxE,sizeof(tnsMEdge*));
- if(mo->Base.Type!=TNS_OBJECT_MESH||!mo->mv.pFirst){ return; }
- for(tnsMEdge* e=mo->me.pFirst;e;e=e->Item.pNext){
- arrEnsureLength(&sd->RefsE, e->i, &sd->maxE, sizeof(tnsObject*));
- sd->RefsE[e->i]=e; sd->nextE=TNS_MAX2(e->i, sd->nextE);
- }
- sd->nextE++;
- }
- void la_PopulateSelectDataPrimitives(MSelectData* sd, tnsMeshObject* mo, tnsCamera* camera, int WhatPrim, int SelectThrough){
- int DoVerts=(WhatPrim==LA_CANVAS_SELECT_MODE_VERTS),DoEdges=(WhatPrim==LA_CANVAS_SELECT_MODE_EDGES);
- int Knife=(WhatPrim==LA_CANVAS_SELECT_MODE_KNIFE);
- if(DoVerts || Knife){ la_PopulateSelectVerts(sd,mo); }
- if(DoEdges || Knife){ la_PopulateSelectEdges(sd,mo); }
- int w=sd->Color->Width, h=sd->Color->Height;
- tnsUnbindTexture(); tnsUniformUseTexture(T->immShader,0,0); tnsUseMultiplyColor(0);
- tnsEnableShaderv(T->SelectionShader);
- 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);
- tnsPushMatrix(); tnsApplyModelMatrix(mo->Base.GlobalTransform);glEnable(GL_DEPTH_TEST);
- if(!SelectThrough){
- glDepthMask(GL_TRUE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- tnsUniformUseOffset(T->SelectionShader,0);
- tnsDrawBatch(mo->Batch,"body",0,0);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- }
- glDepthMask(GL_FALSE);
- tnsUniformUseOffset(T->SelectionShader,1);
- if(DoEdges || Knife){ tnsDrawBatch(mo->Batch, "edges_select",0,0); }
- if(DoVerts || Knife){ tnsDrawBatch(mo->Batch, "verts_select",0,0); }
- tnsUniformUseOffset(T->SelectionShader,0);
- tnsPopMatrix();
- glDisable(GL_DEPTH_TEST);
- tnsEnableShaderv(T->immShader);
- }
- void la_PadSelectionBuffer(uint8_t* buf, int w, int h, int sx, int sy, int ex, int ey, int real_endx){
- if(!sx&&!sy&&!ex&&!ey) return;
- uint8_t* pad=calloc(1,sizeof(uint8_t)*4*w*h);
- for(int i=0;i<h;i++){
- if(i<sy || i>=h-ey){ memset(&pad[i*w*4],0,w*4); continue; }
- for(int j=0;j<w;j++){
- if(j<sx || j>=w-sx){ memset(&pad[(i*w+j)*4],0,4); continue; }
- memcpy(&pad[(i*w+j)*4], &buf[((i-sy)*(real_endx-sx)+j-sx)*4], 4);
- }
- }
- memcpy(buf,pad,sizeof(uint8_t)*4*w*h);
- free(pad);
- }
- uint8_t* la_ReadSelection(MSelectData* sd, u8bit* buf, int x, int y, int w, int h){
- glFlush(); glFinish(); glGetError();
- glBindFramebuffer(GL_READ_FRAMEBUFFER, sd->FBO->FboHandle);
- glReadBuffer(GL_COLOR_ATTACHMENT0);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glReadPixels(x,y,w,h, GL_RGBA, GL_UNSIGNED_BYTE, buf);
- return buf;
- }
- uint8_t* la_ReadSelectionRadius(MSelectData* sd, int uix, int uiy, int radius){
- int w=radius*2; int vh=sd->Color->Height,vw=sd->Color->Width;
- uint8_t* buf=calloc(1,sizeof(uint8_t)*4*w*w);
- int startx=uix-radius, starty=vh-uiy-radius, endx=uix+radius, endy=vh-uiy+radius;
- TNS_CLAMP(startx,0,vw);TNS_CLAMP(endx,0,vw);TNS_CLAMP(starty,0,vh);TNS_CLAMP(endy,0,vh);
- int _startx=TNS_MAX2(startx,0), _starty=TNS_MAX2(starty,0), _endx=TNS_MIN2(endx,vw), _endy=TNS_MIN2(endy,vh);
- la_ReadSelection(sd, buf, _startx, _starty, _endx-_startx, _endy-_starty);
- la_PadSelectionBuffer(buf, w, w, _startx-startx, _starty-starty, endx-_endx, endy-_endy,_endx);
- return buf;
- }
- uint8_t* la_ReadSelectionBox(MSelectData* sd, int uix, int uiy, int uix2, int uiy2){
- int vh=sd->Color->Height,vw=sd->Color->Width;
- if(uix2<uix) LA_SWAP(int,uix,uix2); if(uiy2<uiy) LA_SWAP(int,uiy,uiy2);
- TNS_CLAMP(uix,0,vw);TNS_CLAMP(uix2,0,vw);TNS_CLAMP(uiy,0,vh);TNS_CLAMP(uiy2,0,vh);
- int w=uix2-uix, h=uiy2-uiy;
- uint8_t* buf=calloc(1,sizeof(uint8_t)*4*w*h);
- int startx=uix, starty=vh-uiy2, endx=uix+w, endy=starty+h;
- int _startx=TNS_MAX2(startx,0), _starty=TNS_MAX2(starty,0), _endx=TNS_MIN2(endx,vw), _endy=TNS_MIN2(endy,vh);
- la_ReadSelection(sd, buf, _startx, _starty, _endx-_startx, _endy-_starty);
- la_PadSelectionBuffer(buf, w, h, _startx-startx, _starty-starty, endx-_endx, endy-_endy,_endx);
- return buf;
- }
- int la_SelectGetClosest(MSelectData* sd, int uix, int uiy, int radius, int *ElemType){
- *ElemType=0; uint8_t* buf=la_ReadSelectionRadius(sd, uix, uiy, radius); if(!buf) return 0;
- int w=radius*2; int MinD=INT_MAX,MinDe=INT_MAX; int MinID=0,MinIDe=0, d, elemtype=0;
- for(int i=0;i<w;i++){
- for(int j=0;j<w;j++){
- uint8_t* p=&buf[(i*w+j)*4]; int id=(p[0])|(p[1]<<8)|((p[2]<<16)&(~TNS_MMESH_TYPE_BIT)); if(!id){continue;}
- d=tnsDistIdv2(i,j, radius, radius); elemtype=((p[2]<<16)&TNS_MMESH_TYPE_BIT);
- if(elemtype==TNS_MMESH_EDGE_BIT){ if(d<MinDe){ MinDe=d; MinIDe=id; } }
- elif(d<MinD){ MinD=d; MinID=id; }
- //printf("%d ",buf[(i*w+j)*4]);
- }
- //printf("\n");
- }
- //printf("%d %d\n",MinID, MinIDe);
- free(buf);
- if(MinID && MinIDe){ if(MinD<MinDe*5){ *ElemType=0; return MinID; } }
- if(MinIDe){ *ElemType=TNS_MMESH_EDGE_BIT; return MinIDe; }
- if(MinID){ *ElemType=0; return MinID; }
- *ElemType=0; return 0;
- }
- int* la_SelectGetBox(MSelectData* sd, int uix, int uiy, int uix2, int uiy2, int* r_length){
- uint8_t* buf=la_ReadSelectionBox(sd, uix, uiy, uix2, uiy2); if(!buf) return 0;
- int vh=sd->Color->Height,vw=sd->Color->Width;
- if(uix2<uix) LA_SWAP(int,uix,uix2); if(uiy2<uiy) LA_SWAP(int,uiy,uiy2);
- TNS_CLAMP(uix,0,vw);TNS_CLAMP(uix2,0,vw);TNS_CLAMP(uiy,0,vh);TNS_CLAMP(uiy2,0,vh);
- int w=uix2-uix, h=uiy2-uiy;
- int* ids=0; int next=0,max=0;
- arrEnsureLength(&ids, next, &max, sizeof(int));
- for(int i=0;i<h;i++){
- for(int j=0;j<w;j++){
- uint8_t* p=&buf[(i*w+j)*4]; int id=(p[0])|(p[1]<<8)|((p[2]<<16)&(~TNS_MMESH_TYPE_BIT));
- if(id){ int found=0;
- for(int a=0;a<next;a++){ if(ids[a]==id){ found=1; break; } }
- if(!found){
- arrEnsureLength(&ids, next, &max, sizeof(int)); ids[next]=id; next++; }
- }
- }
- }
- free(buf);
- *r_length=next;
- return ids;
- }
- void la_FreeSelectData(MSelectData* sd){
- tnsDelete2DOffscreen(sd->FBO);
- free(sd->RefsV);
- free(sd->RefsE);
- memFree(sd);
- }
- void* la_SelectGetRef(MSelectData* sd, int id, int elemtype){
- if(!elemtype){ if(id>=0 && id<sd->nextV){ return sd->RefsV[id]; } }
- elif(elemtype==TNS_MMESH_EDGE_BIT){ if(id>=0 && id<sd->nextE){ return sd->RefsE[id]; } }
- return 0;
- }
- int OPCHK_ViewportAndSceneExists(laPropPack *This, laStringSplitor *ss){
- if(!This || !This->EndInstance){ return 0; } laCanvasExtra* ex=This->EndInstance;
- laUiItem* ui=ex->ParentUi; tnsObject* root=ui?ui->PP.EndInstance:0;
- if(!ex->ViewingCamera || !root){ return 0; }
- return 1;
- }
- void la_DoObjectSelect(tnsObject* root, tnsObject* o, laCanvasExtra* e, int DeselectAll, int Select, int Toggle){
- if(DeselectAll){ tnsDeselectAllObjects(root); memAssignRef(root,&root->Active,0); }
- if(o){ tnsSelectObject(o, Select, o==root->Active?0:Toggle); memAssignRef(root,&root->Active,o); }
- }
- void la_DoMeshSelect(tnsMeshObject* mo, void* p, int WhatPrim, int DeselectAll, int Select, int Toggle){
- if(DeselectAll){ tnsMMeshDeselectAll(mo); }
- if(p){ if(WhatPrim==LA_CANVAS_SELECT_MODE_VERTS) tnsMMeshSelectVert(mo,p,Select,Toggle);
- elif(WhatPrim==LA_CANVAS_SELECT_MODE_EDGES) tnsMMeshSelectEdge(mo,p,Select,Toggle); }
- }
- #define LA_SELECT_MODE_BOX 1
- STRUCTURE(MSelectExtra){
- MSelectData* sd;
- tnsObject* root;
- tnsObject* mo;
- tnsCamera* cam;
- int Mode;
- int InSelect;
-
- laListHandle KnifeElements;
- void* PendingElem; int PendingElemType, BatchDirty;
- int IsLoop;
- };
- int OPINV_Select(laOperator *a, laEvent *e){
- 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;
- int is_geo=0, SelectMode=ex->SelectMode, ring_band=0;
- if(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"), "toggle")){
- if(mo && mo->Base.Type==TNS_OBJECT_MESH && mo->Mode==TNS_MESH_EDIT_MODE){
- if(tnsMMeshAnySelected(mo)) tnsMMeshDeselectAll(mo); else tnsMMeshSelectAll(mo);
- tnsInvalidateMeshBatch(mo); is_geo=1;
- }else{
- if(tnsAnyObjectsSelected(root)) tnsDeselectAllObjects(root); else tnsSelectAllObjects(root);
- }
- laNotifyUsers("tns.world"); laRecordAndPush(0,"tns.world", "Toggle selection",is_geo?TNS_HINT_GEOMETRY:TNS_HINT_TRANSFORM);
- return LA_FINISHED;
- }
- int spk=e->SpecialKeyBit & (LA_KEY_CTRL|LA_KEY_ALT);
- if(spk==LA_KEY_ALT){ ring_band=1; SelectMode=LA_CANVAS_SELECT_MODE_EDGES; }
- elif(spk==(LA_KEY_CTRL|LA_KEY_ALT)){ ring_band=2; SelectMode=LA_CANVAS_SELECT_MODE_EDGES; }
-
- MSelectData* sd=la_InitSelectData(ex->OffScr->pColor[0]->Width, ex->OffScr->pColor[0]->Height, c);
- int DeselectAll=1;
- int Append=e->SpecialKeyBit&LA_KEY_SHIFT; if(Append) DeselectAll=0;
-
- if(mo && mo->Base.Type==TNS_OBJECT_MESH && mo->Mode==TNS_MESH_EDIT_MODE){
- la_PopulateSelectDataPrimitives(sd, mo, ex->ViewingCamera, SelectMode, ex->SelectThrough);
- if(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"), "box")){
- MSelectExtra* se=memAcquire(sizeof(MSelectExtra));
- ex->OnX=e->x; ex->OnX=e->y;
- a->CustomData=se; se->sd=sd; se->Mode=LA_SELECT_MODE_BOX; se->mo=mo; se->cam=c; ex->DrawCursor=1; se->root=root; return LA_RUNNING;
- }
- int elemtype,id=la_SelectGetClosest(sd, e->x-ui->L, e->y-ui->U, LA_RH,&elemtype)-1;
- void* p=la_SelectGetRef(sd,id,elemtype);
- la_DoMeshSelect(mo, p, SelectMode, DeselectAll, 1, 1); tnsMMeshEnsureSelection(mo,ex->SelectMode);
- if(ring_band && p){
- tnsMMeshSelectRingBandFrom(mo,p,ring_band,1,Append); tnsMMeshEnsureSelection(mo,ex->SelectMode);
- }
- tnsInvalidateMeshBatch(mo);
- laNotifyUsers("tns.world"); laRecordAndPush(0,"tns.world","Mesh selection",TNS_HINT_GEOMETRY);
- }else{
- la_PopulateSelectDataObjects(sd,root,ex->ViewingCamera);
- if(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"), "box")){
- MSelectExtra* se=memAcquire(sizeof(MSelectExtra));
- ex->OnX=e->x; ex->OnX=e->y;
- a->CustomData=se; se->sd=sd; se->Mode=LA_SELECT_MODE_BOX; se->cam=c; ex->DrawCursor=1; se->root=root; return LA_RUNNING;
- }
- int elemtype,id=la_SelectGetClosest(sd, e->x-ui->L, e->y-ui->U, LA_RH*2,&elemtype);
- void* p=la_SelectGetRef(sd,id,elemtype); if(p){ la_DoObjectSelect(root, p, ex, DeselectAll, 1, 1); }
- else{ la_DoObjectSelect(root, 0, ex, DeselectAll, 1, 1); }
- laNotifyUsers("tns.world"); laRecordAndPush(0,"tns.world","Object selection",TNS_HINT_TRANSFORM);
- }
- la_FreeSelectData(sd);
-
- return LA_FINISHED_PASS;
- }
- int OPMOD_Select(laOperator *a, laEvent *e){
- 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;
- MSelectExtra* se=a->CustomData;
- if(e->Type==LA_L_MOUSE_DOWN){ se->InSelect=1; ex->DrawCursor=2; ex->ClickedX=e->x; ex->ClickedY=e->y; laRedrawCurrentPanel(); }
- if(e->Type&LA_MOUSE_EVENT){ ex->OnX=e->x; ex->OnY=e->y; laRedrawCurrentPanel(); }
- if(e->Type==LA_R_MOUSE_DOWN || (e->Type == LA_KEY_DOWN && e->key==LA_KEY_ESCAPE)){
- ex->DrawCursor=0; la_FreeSelectData(se->sd); memFree(se); laNotifyUsers("tns.world"); return LA_FINISHED;
- }
- int DeselectAll=1;
- int Append=e->SpecialKeyBit&LA_KEY_SHIFT; if(Append) DeselectAll=0;
- int Remove=e->SpecialKeyBit&LA_KEY_ALT; if(Remove) DeselectAll=0;
- int is_geo=0;
- if(se->InSelect && e->Type==LA_L_MOUSE_UP){
- if(mo && mo->Base.Type==TNS_OBJECT_MESH && mo->Mode==TNS_MESH_EDIT_MODE){
- la_DoMeshSelect(mo, 0, ex->SelectMode, DeselectAll, 0, 0);
- int len; int* ids=la_SelectGetBox(se->sd, ex->ClickedX-ui->L, ex->ClickedY-ui->U, e->x-ui->L, e->y-ui->U, &len);
- for(int i=0;i<len;i++){
- int id=ids[i]-1; void* p=la_SelectGetRef(se->sd,id,ex->SelectMode==LA_CANVAS_SELECT_MODE_EDGES?TNS_MMESH_EDGE_BIT:0);
- la_DoMeshSelect(mo, p, ex->SelectMode, 0, !Remove, 0);
- }
- tnsMMeshEnsureSelection(mo,ex->SelectMode);
- tnsInvalidateMeshBatch(mo); is_geo=1;
- }else{
- la_DoObjectSelect(se->root, 0, ex, DeselectAll, 0, 0);
- int len; int* ids=la_SelectGetBox(se->sd, ex->ClickedX, ex->ClickedY, e->x-ui->L, e->y-ui->U, &len);
- for(int i=0;i<len;i++){
- int id=ids[i]; void* p=la_SelectGetRef(se->sd,id,0);
- if(p){ la_DoObjectSelect(se->root, p, ex, 0, !Remove, 0); }
- }
- }
- laNotifyUsers("tns.world"); laRecordAndPush(0,"tns.world","Box selection",is_geo?TNS_HINT_GEOMETRY:TNS_HINT_TRANSFORM);
- ex->DrawCursor=0;
- la_FreeSelectData(se->sd); memFree(se);
- laRedrawCurrentPanel();
- return LA_FINISHED;
- }
-
- return LA_RUNNING;
- }
- #define LA_TRANSFORM_MODE_GRAB 1
- #define LA_TRANSFORM_MODE_ROTATE 2
- #define LA_TRANSFORM_MODE_SCALE 3
- #define LA_TRANSFORM_RESTORE_LOC 1
- #define LA_TRANSFORM_RESTORE_ROT 2
- #define LA_TRANSFORM_RESTORE_SCA 3
- STRUCTURE(MTOrigObject){
- tnsObject* o;
- tnsMatrix44d Global;
- tnsMatrix44d Local;
- int Discard;
- };
- STRUCTURE(MTOrigMVert){
- tnsVector3d p;
- tnsVector3d origp;
- tnsMVert* mv;
- };
- STRUCTURE(MTransformData){
- tnsMatrix44d Delta;
- tnsMatrix44d ViewProjection;
- tnsVector4d Up,Right,Foward;
- tnsVector4d TCenter;
- int CenterX,CenterY; real Initial;
- tnsObject* mo; tnsMatrix44d obmatinv,deltainv;
- tnsCamera* c; tnsObject* root;
- int w,h;
- void* Originals; int next,max;
- int mode;
- int LockAxis[3];
- int UseLocal;
- real DeltaVal, UserDeltaVal;
- laStringEdit* Entry; int UseUserDelta;
- int CanvasDeltaMode;
- };
- MTransformData* la_InitTransformData(int w, int h, tnsCamera* c, int CanvasDeltaMode){
- 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;
- tnsGetCameraMovingDeltas(c,w,h,0,-1,pu); pu[2]=0; pu[3]=0;
- tnsMatrix44d inv; tnsInverse44d(inv,c->Base.GlobalTransform);
- 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, "");
- 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); }
- void la_GetTransformInitialRotation(MTransformData* td, laUiItem* ui, int x, int y){ td->Initial=atan2(y-ui->U-td->CenterY,x-ui->L-td->CenterX); }
- void la_GetTransformCenter2D(MTransformData* td){
- tnsVector4d vp; tnsApplyTransform44d(vp,td->ViewProjection,td->TCenter);
- if(td->c->CameraType==TNS_CAMERA_PERSP){ tnsVectorMultiSelf3d(vp, 1/vp[3]); }
- td->CenterX = (vp[0]/2+0.5f)*td->w; td->CenterY=(-vp[1]/2+0.5f)*td->h;
- if(td->CenterX<0||td->CenterY<0) { td->CenterX=td->w/2; td->CenterY=td->h/2; }
- }
- int la_AddTransformObjectsRecursive(MTransformData* td, tnsObject*root){
- int any=0; for(laListItemPointer* lip=root->ChildObjects.pFirst;lip;lip=lip->pNext){
- tnsObject* o=lip->p; if(o->ChildObjects.pFirst) any+=la_AddTransformObjectsRecursive(td,o);
- if(!(o->Flags&TNS_OBJECT_FLAGS_SELECTED)) continue;
- arrEnsureLength(&td->Originals, td->next, &td->max, sizeof(MTOrigObject));
- MTOrigObject* to=arrElement(td->Originals, td->next, sizeof(MTOrigObject)); td->next++; to->o=o;
- memcpy(to->Global, o->GlobalTransform, sizeof(tnsMatrix44d));
- memcpy(to->Local, o->SelfTransform, sizeof(tnsMatrix44d));
- tnsVectorAccum3d(td->TCenter,o->GLocation); any++;
- int discard=0; tnsObject* po=o; while(po=po->ParentObject){ if(po->Flags&TNS_OBJECT_FLAGS_SELECTED){ discard=1; break;} } if(discard) to->Discard=1;
- }
- return any;
- }
- int la_PopulateTransformObjects(MTransformData* td, tnsObject* root){
- arrEnsureLength(&td->Originals, 0, &td->max, sizeof(MTOrigObject));
- int any=la_AddTransformObjectsRecursive(td,root);
- tnsVectorMultiSelf3d(td->TCenter, 1.0f/any);
- la_GetTransformCenter2D(td);
- return any;
- }
- int la_PopulateTransformVerticies(MTransformData* td, tnsMeshObject* mo){
- int any=0; td->mo=mo;
- arrEnsureLength(&td->Originals, 0, &td->max, sizeof(MTOrigMVert));
- tnsInverse44d(td->obmatinv, mo->Base.GlobalTransform);
- tnsInverse44d(td->deltainv, mo->Base.DeltaTransform);
- for(tnsMVert* mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){
- if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue;
- //printf("v %d ",mv->i);
- arrEnsureLength(&td->Originals, td->next, &td->max, sizeof(MTOrigMVert));
- MTOrigMVert* to=arrElement(td->Originals, td->next, sizeof(MTOrigMVert)); td->next++; to->mv=mv;
- tnsApplyTransform43d(to->p, mo->Base.GlobalTransform, mv->p);
- memcpy(to->origp, mv->p, sizeof(tnsVector3d)); any++;
- tnsVectorAccum3d(td->TCenter,to->p);
- }
- //printf(" [totmv %d]\n",mo->totmv);
- tnsVectorMultiSelf3d(td->TCenter, 1.0f/any);
- la_GetTransformCenter2D(td);
- 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); }
- td->DeltaVal=tnsLength3d(use_delta);
- if(td->UseUserDelta){
- tnsVectorMultiSelf3d(use_delta,1/tnsLength3d(use_delta)*td->UserDeltaVal);
- tnsVector3d lock={ td->LockAxis[0], td->LockAxis[1], td->LockAxis[2] };
- real dir=tnsDot3d(use_delta, lock, 0); tnsVectorMultiSelf3d(use_delta,(td->UserDeltaVal*dir<=0)?-1:1);
- td->DeltaVal=td->UserDeltaVal;
- }
- 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));
- if(to->Discard){ tnsSelfMatrixChanged(to->o,1); continue; }
- if(td->CanvasDeltaMode) tnsGlobalMatrixChangedForDelta(to->o, 0); else tnsGlobalMatrixChanged(to->o, 0);
- if(td->UseLocal){
- if(td->CanvasDeltaMode) tnsMoveObjectDelta(to->o, LA_COLOR3(use_delta));
- else tnsMoveObjectLocal(to->o, LA_COLOR3(use_delta));
- }else{
- if(td->CanvasDeltaMode) tnsMoveObjectGlobalForDelta(to->o, LA_COLOR3(use_delta));
- else tnsMoveObjectGlobal(to->o, LA_COLOR3(use_delta));
- }
- }
- }else{
- tnsMakeTranslationMatrix44d(trans, LA_COLOR3(use_delta)); tnsMatrix44d final;
- if(!td->UseLocal) tnsMultiply44d(final,td->obmatinv,trans);
- else tnsMultiply44d(final,trans,td->obmatinv);
- for(int i=0;i<td->next;i++){ MTOrigMVert* to=arrElement(td->Originals, i, sizeof(MTOrigMVert));
- tnsApplyTransform43d(to->mv->p, final, to->p);
- }
- tnsInvalidateMeshBatch(td->mo); tnsMMeshCalculateNormal(td->mo);
- }
- }
- void la_ApplyScale(MTransformData* td, int uix, int uiy){
- tnsMatrix44d trans; real d=tnsDistIdv2(uix,uiy,td->CenterX,td->CenterY); if(!td->Initial){ td->Initial=100; }
- real s=d/td->Initial; tnsVector3d gp;
- td->DeltaVal=s; if(td->UseUserDelta) td->DeltaVal=s=td->UserDeltaVal;
- 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));
- if(to->Discard){ tnsSelfMatrixChanged(to->o,1); continue; }
- if(td->CanvasDeltaMode) tnsGlobalMatrixChangedForDelta(to->o, 0); else tnsGlobalMatrixChanged(to->o, 0);
- if(td->CanvasDeltaMode) tnsScaleObjectDelta(to->o,s,LA_COLOR3(td->TCenter));
- else tnsScaleObject(to->o, s, LA_COLOR3(td->TCenter));
- }
- }else{
- tnsVector3d use_delta={s,s,s};
- if(td->LockAxis[0]>0){ use_delta[1]=use_delta[2]=1;}
- if(td->LockAxis[1]>0){ use_delta[0]=use_delta[2]=1;}
- if(td->LockAxis[2]>0){ use_delta[0]=use_delta[1]=1;}
- if(td->LockAxis[0]<0){ use_delta[0]=1; }
- if(td->LockAxis[1]<0){ use_delta[1]=1; }
- if(td->LockAxis[2]<0){ use_delta[2]=1; }
- tnsMakeScaleMatrix44d(trans,LA_COLOR3(use_delta));
- tnsMatrix44d t1,t2,t3; tnsMakeTranslationMatrix44d(t1,LA_COLOR3(td->TCenter)); tnsInverse44d(t2,t1);
- tnsMatrix44d final; tnsMultiply44d(t3,t1,trans); tnsMultiply44d(t1,t3,t2);
- if(!td->UseLocal) tnsMultiply44d(final,td->obmatinv,t1);
- else tnsMultiply44d(final,t1,td->obmatinv);
- for(int i=0;i<td->next;i++){ MTOrigMVert* to=arrElement(td->Originals, i, sizeof(MTOrigMVert));
- tnsApplyTransform43d(to->mv->p, final, to->p);
- }
- tnsInvalidateMeshBatch(td->mo); tnsMMeshCalculateNormal(td->mo);
- }
- }
- 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->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[2]){ LimFoward[2]=1; }
- 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));
- if(to->Discard){ tnsSelfMatrixChanged(to->o,1); continue; }
- if(td->CanvasDeltaMode) tnsGlobalMatrixChangedForDelta(to->o, 0); else tnsGlobalMatrixChanged(to->o, 0);
- if(td->UseLocal){
- if(td->CanvasDeltaMode) tnsRotateObjectDelta(to->o,LA_COLOR3(use_forward),angle,LA_COLOR3(td->TCenter));
- else tnsRotateObjectLocal(to->o,LA_COLOR3(use_forward),angle,LA_COLOR3(td->TCenter));
- }else{
- if(td->CanvasDeltaMode) tnsRotateObjectGlobalForDelta(to->o,LA_COLOR3(use_forward),angle,LA_COLOR3(td->TCenter));
- else tnsRotateObjectGlobal(to->o,LA_COLOR3(use_forward),angle,LA_COLOR3(td->TCenter));
- }
- }
- }else{
- tnsMakeRotationMatrix44d(trans, angle, LA_COLOR3(use_forward));
- tnsMatrix44d t1,t2,t3; tnsMakeTranslationMatrix44d(t1,LA_COLOR3(td->TCenter)); tnsInverse44d(t2,t1);
- tnsMatrix44d final; tnsMultiply44d(t3,t1,trans); tnsMultiply44d(t1,t3,t2);
- if(!td->UseLocal) tnsMultiply44d(final,td->obmatinv,t1);
- else tnsMultiply44d(final,t1,td->obmatinv);
- for(int i=0;i<td->next;i++){ MTOrigMVert* to=arrElement(td->Originals, i, sizeof(MTOrigMVert));
- tnsApplyTransform43d(to->mv->p, final, to->p);
- }
- tnsInvalidateMeshBatch(td->mo); tnsMMeshCalculateNormal(td->mo);
- }
- }
- void la_CancelTransformObjects(MTransformData* td){
- if(!td->mo){
- for(int i=0;i<td->next;i++){ MTOrigObject* to=arrElement(td->Originals, i, sizeof(MTOrigObject));
- if(to->Discard){ tnsSelfMatrixChanged(to->o,1); continue; }
- memcpy(to->o->GlobalTransform, to->Global,sizeof(tnsMatrix44d));
- if(td->CanvasDeltaMode) tnsGlobalMatrixChangedForDelta(to->o, 1);
- else tnsGlobalMatrixChanged(to->o, 1);
- }
- }else{
- for(int i=0;i<td->next;i++){ MTOrigMVert* to=arrElement(td->Originals, i, sizeof(MTOrigMVert)); tnsVectorCopy3d(to->origp,to->mv->p); }
- tnsInvalidateMeshBatch(td->mo);
- }
- }
- void la_RecordTransformDifferences(MTransformData* td){
- if(!td->mo){
- for(int i=0;i<td->next;i++){ MTOrigObject* to=arrElement(td->Originals, i, sizeof(MTOrigObject));
- laRecordInstanceDifferences(to->o, "tns_object");
- } laPushDifferences(td->mode==LA_TRANSFORM_MODE_GRAB?"Moved objects":td->mode==LA_TRANSFORM_MODE_ROTATE?"Rotated objects":"Scaled objects", TNS_HINT_TRANSFORM);
- }else{
- laRecordInstanceDifferences(td->mo, "tns_mesh_object");
- laPushDifferences(td->mode==LA_TRANSFORM_MODE_GRAB?"Moved primitives":td->mode==LA_TRANSFORM_MODE_ROTATE?"Rotated primitives":"Scaled primitives", TNS_HINT_GEOMETRY);
- tnsInvalidateMeshBatch(td->mo);
- }
- }
- void la_FreeTransformData(MTransformData* td){
- free(td->Originals);
- strEndEdit(&td->Entry, 1);
- memFree(td);
- }
- void la_MakeTransformOperatorHint(laOperator* a, MTransformData* td){
- strSafeDestroy(&a->RuntimeHint);
- strSafePrint(&a->RuntimeHint, "%s ",
- td->mode==LA_TRANSFORM_MODE_GRAB?"Grab":td->mode==LA_TRANSFORM_MODE_ROTATE?"Rotate":td->mode==LA_TRANSFORM_MODE_SCALE?"Scale":"");
- char* entry=strGetEditString(td->Entry,0);
- strSafePrint(&a->RuntimeHint, "Delta: %.3lf [🔢 %s] 🆇🆈🆉 Lock axis: %s 🈳 %s ", td->DeltaVal, (entry&&entry[0])?entry:"Type...",
- td->LockAxis[0]?"X":td->LockAxis[1]?"Y":td->LockAxis[2]?"Z":"None",
- td->UseLocal?"Global/[Local]":"[Global]/Local");
- free(entry);
- if(td->mode==LA_TRANSFORM_MODE_GRAB){ strSafePrint(&a->RuntimeHint, "🡅🆇🆈🆉 Reverse: %s ",
- (td->LockAxis[0]<0||td->LockAxis[1]<0||td->LockAxis[2]<0)?"Yes":"No"); }
- if(td->mode!=LA_TRANSFORM_MODE_GRAB){ strSafePrint(&a->RuntimeHint,"🅶 Grab "); }
- if(td->mode!=LA_TRANSFORM_MODE_SCALE){ strSafePrint(&a->RuntimeHint,"🆂 Scale "); }
- if(td->mode!=LA_TRANSFORM_MODE_ROTATE){ strSafePrint(&a->RuntimeHint,"🆁 Rotate "); }
- }
- void la_RestoreTransform(tnsObject* ob, int restore_type, int restore_delta){
- if(restore_delta){
- if(restore_type==LA_TRANSFORM_RESTORE_LOC){ tnsVectorSet3(ob->DLocation,0,0,0); }
- elif(restore_type==LA_TRANSFORM_RESTORE_ROT){ tnsVectorSet3(ob->DRotation,0,0,0); }
- elif(restore_type==LA_TRANSFORM_RESTORE_SCA){ ob->DScale=1; }
- tnsDeltaTransformValueChanged(ob);
- }else{
- if(restore_type==LA_TRANSFORM_RESTORE_LOC){ tnsVectorSet3(ob->Location,0,0,0); }
- elif(restore_type==LA_TRANSFORM_RESTORE_ROT){ tnsVectorSet3(ob->Rotation,0,0,0); }
- elif(restore_type==LA_TRANSFORM_RESTORE_SCA){ ob->Scale=1; }
- tnsSelfTransformValueChanged(ob);
- }
- }
- int la_InitTransform(laOperator* a, laEvent* e, int mode, int restore_type, int restore_delta){
- 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;
- MTransformData* td=la_InitTransformData(ex->OffScr->pColor[0]->Width, ex->OffScr->pColor[0]->Height, c, ex->DeltaMode);
- a->CustomData = td;
- td->mode=mode;
- td->root=root;
- int ret=0;
- if(mo && mo->Base.Type==TNS_OBJECT_MESH && mo->Mode==TNS_MESH_EDIT_MODE){
- if(la_PopulateTransformVerticies(td, mo)){ ex->ClickedX=e->x; ex->ClickedY=e->y; ret=1; }
- }else{
- if(la_PopulateTransformObjects(td,root)){ ex->ClickedX=e->x; ex->ClickedY=e->y; ret=1; }
- if(ret && restore_type){
- for(int i=0;i<td->next;i++){ MTOrigObject* ob=arrElement(td->Originals, i, sizeof(MTOrigObject));
- la_RestoreTransform(ob->o,restore_type,restore_delta);
- }
- la_RecordTransformDifferences(td); laNotifyUsers("tns.world"); la_FreeTransformData(td);
- return 0;
- }
- }
-
- if(ret){
- if(mode==LA_TRANSFORM_MODE_SCALE){ la_GetTransformInitialScale(td,ui,e->x,e->y); ex->DrawCursor=LA_CANVAS_CURSOR_ARROW; }
- elif(mode==LA_TRANSFORM_MODE_ROTATE){ la_GetTransformInitialRotation(td,ui,e->x,e->y); ex->DrawCursor=LA_CANVAS_CURSOR_ARROW; }
- ex->TargetX=td->CenterX+ui->L; ex->TargetY=td->CenterY+ui->U; ex->OnX=e->x; ex->OnY=e->y;
- la_MakeTransformOperatorHint(a, td);
- laNotifyUsers("tns.world"); return 1;
- }
- return 0;
- }
- int OPINV_Grab(laOperator *a, laEvent *e){
- if(la_InitTransform(a, e, LA_TRANSFORM_MODE_GRAB,0,0)) return LA_RUNNING; return LA_FINISHED_PASS;
- }
- int OPINV_Scale(laOperator *a, laEvent *e){
- if(la_InitTransform(a, e, LA_TRANSFORM_MODE_SCALE,0,0)) return LA_RUNNING; return LA_FINISHED_PASS;
- }
- int OPINV_Rotate(laOperator *a, laEvent *e){
- if(la_InitTransform(a, e, LA_TRANSFORM_MODE_ROTATE,0,0)) return LA_RUNNING; return LA_FINISHED_PASS;
- }
- int OPMOD_Transformation(laOperator *a, laEvent *e){
- 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;
- MTransformData* td=a->CustomData;
- if (e->Input=='x'||e->Input=='y'||e->Input=='z'||e->Input=='g'||e->Input=='s'||e->Input=='r'||
- e->Input=='X'||e->Input=='Y'||e->Input=='Z'||e->Input==' '){ /*pass*/ }
- else{ la_ProcessTextEdit(e, td->Entry, 0); }
- char* entered;
- if(entered=strGetEditString(td->Entry,0)){ int status;
- if((status=sscanf(entered,"%lf",&td->UserDeltaVal)) && status!=EOF) td->UseUserDelta=1; else td->UseUserDelta=0;
- td->UserDeltaVal=fabs(td->UserDeltaVal); for(char*pc=entered;*pc;pc++){ if(*pc=='-') td->UserDeltaVal=-td->UserDeltaVal; } free(entered);
- }
- if(e->Type==LA_KEY_DOWN){
- int Other=1; if(e->SpecialKeyBit&LA_KEY_SHIFT){ Other=-1; }
- if(e->key=='x'){ td->LockAxis[0]=Other*((Other<0&&td->LockAxis[0])?td->LockAxis[0]:!td->LockAxis[0]); td->LockAxis[1]=td->LockAxis[2]=0; }
- if(e->key=='y'){ td->LockAxis[1]=Other*((Other<0&&td->LockAxis[1])?td->LockAxis[1]:!td->LockAxis[1]); td->LockAxis[0]=td->LockAxis[2]=0; }
- if(e->key=='z'){ td->LockAxis[2]=Other*((Other<0&&td->LockAxis[2])?td->LockAxis[2]:!td->LockAxis[2]); td->LockAxis[0]=td->LockAxis[1]=0; }
- if(e->key=='g' && td->mode!=LA_TRANSFORM_MODE_GRAB){ td->mode=LA_TRANSFORM_MODE_GRAB; ex->DrawCursor=0; }
- if(e->key=='s' && td->mode!=LA_TRANSFORM_MODE_SCALE){ td->mode=LA_TRANSFORM_MODE_SCALE; la_GetTransformInitialScale(td,ui,e->x,e->y);ex->DrawCursor=LA_CANVAS_CURSOR_ARROW; }
- if(e->key=='r' && td->mode!=LA_TRANSFORM_MODE_ROTATE){ td->mode=LA_TRANSFORM_MODE_ROTATE; la_GetTransformInitialRotation(td,ui,e->x,e->y);ex->DrawCursor=LA_CANVAS_CURSOR_ARROW; }
- if(e->key==' '){ td->UseLocal=!td->UseLocal; }
- }
- if(e->Type==LA_MOUSEMOVE || e->Type==LA_KEY_DOWN){
- switch(td->mode){
- case LA_TRANSFORM_MODE_GRAB: la_ApplyTranslation(td,e->x-ex->ClickedX, e->y-ex->ClickedY); break;
- case LA_TRANSFORM_MODE_SCALE: la_ApplyScale(td,e->x-ui->L, e->y-ui->U); break;
- case LA_TRANSFORM_MODE_ROTATE: la_ApplyRotation(td,e->x-ui->L, e->y-ui->U); break;
- default: break;
- }
- ex->OnX=e->x; ex->OnY=e->y;
- laNotifyUsers("tns.world");
- }
- if(e->Type==LA_L_MOUSE_DOWN || (e->Type==LA_KEY_DOWN && e->key==LA_KEY_ENTER)){ ex->DrawCursor=0;
- la_RecordTransformDifferences(td);
- laNotifyUsers("tns.world"); la_FreeTransformData(td); return LA_FINISHED;
- }
- if(e->Type==LA_R_MOUSE_DOWN || e->Type==LA_ESCAPE_DOWN){ ex->DrawCursor=0;
- la_CancelTransformObjects(td); laNotifyUsers("tns.world"); la_FreeTransformData(td); return LA_FINISHED;
- }
- la_MakeTransformOperatorHint(a, td);
- return LA_RUNNING;
- }
- int OPINV_ClearTransformation(laOperator *a, laEvent *e){
- laCanvasExtra* ex=a->This->EndInstance; int restore=0;
- char* channel=strGetArgumentString(a->ExtraInstructionsP,"channel");
- if(channel){
- if(channel[0]=='L' || channel[0]=='l'){ restore=LA_TRANSFORM_RESTORE_LOC; }
- if(channel[0]=='R' || channel[0]=='r'){ restore=LA_TRANSFORM_RESTORE_ROT; }
- if(channel[0]=='S' || channel[0]=='s'){ restore=LA_TRANSFORM_RESTORE_SCA; }
- }else{
- laEnableOperatorPanel(a,a->This,e->x,e->y,150,200,0,0,0,0,0,0,0,0,e); return LA_RUNNING;
- }
- char* dt=strGetArgumentString(a->ExtraInstructionsP,"delta");
- int delta=dt?strSame(dt,"true"):ex->DeltaMode;
- la_InitTransform(a,e,0,restore,delta);
- return LA_FINISHED;
- }
- void laui_ClearTransformation(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
- laColumn* c=laFirstColumn(uil), *cl,*cr; laSplitColumn(uil,c,0.6); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
- laShowItemFull(uil,cl,pp,"_this_M_clear_transformations",0,"channel=loc;text=Location",0,0);
- laShowItemFull(uil,cl,pp,"_this_M_clear_transformations",0,"channel=rot;text=Rotation",0,0);
- laShowItemFull(uil,cl,pp,"_this_M_clear_transformations",0,"channel=sca;text=Scale",0,0);
- laShowItemFull(uil,cr,pp,"_this_M_clear_transformations",0,"channel=loc;text=Delta;delta=true",0,0);
- laShowItemFull(uil,cr,pp,"_this_M_clear_transformations",0,"channel=rot;text=Delta;delta=true",0,0);
- laShowItemFull(uil,cr,pp,"_this_M_clear_transformations",0,"channel=sca;text=Delta;delta=true",0,0);
- }
- int la_ParentableRecursive(tnsObject* root, tnsObject* parent){
- for(laListItemPointer* lip=root->ChildObjects.pFirst;lip;lip=lip->pNext){
- tnsObject* o=lip->p; if((!o) || (!(o->Flags&TNS_OBJECT_FLAGS_SELECTED)) || (o==parent)) continue;
- if(!tnsCheckParentable(o,parent)) return 0;
- if(!la_ParentableRecursive(o,parent)) return 0;
- }return 1;
- }
- void la_MakeParentExecuteRecursive(tnsObject* root, tnsObject* parent, int Unparent, int KeepTransform){
- laListItemPointer* NextLip;
- if(root->Type!=TNS_OBJECT_ROOT){
- if((root->Flags&TNS_OBJECT_FLAGS_SELECTED)&&root->InRoot==parent->InRoot){
- if(Unparent) tnsUnparentObject(root, KeepTransform);
- elif(root!=parent) tnsParentObject(root, parent, KeepTransform);
- }
- }
- for(laListItemPointer* lip=root->ChildObjects.pFirst;lip;lip=NextLip){ NextLip=lip->pNext;
- tnsObject* o=lip->p; if(!o) continue; la_MakeParentExecuteRecursive(o,parent,Unparent,KeepTransform);
- }
- laNotifyUsers("tns.world");
- }
- int OPINV_MakeParent(laOperator *a, laEvent *e){
- 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;
- tnsObject* mo=root->Active;
- int Unparent=0,KeepTransform=1;
- char* action=strGetArgumentString(a->ExtraInstructionsP,"action");
- char* keep=strGetArgumentString(a->ExtraInstructionsP,"keep_transform");
- if(strSame(action,"unparent")){ Unparent=1; }
- if(strSame(keep,"false")){ KeepTransform=0; }
- if(!Unparent){ if((!mo) || (!(mo->Flags&TNS_OBJECT_FLAGS_SELECTED))) return LA_FINISHED;
- if(!la_ParentableRecursive(root,mo)){ laEnableMessagePanel(0,0,"It didn't work","There are loops in parenting",e->x,e->y,0,e); return LA_FINISHED; }
- }
- if(keep){
- la_MakeParentExecuteRecursive(root,mo,Unparent,KeepTransform);
- laRecordInstanceDifferences(T->World, "tns_world"); laPushDifferences(Unparent?"Unparent":"Parent", TNS_HINT_TRANSFORM);
- return LA_FINISHED;
- }
- laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
- return LA_RUNNING;
- }
- void laui_MakeParent(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
- laColumn* c=laFirstColumn(uil);
- laShowItemFull(uil,c,pp,"_this_M_make_parent",0,"action=parent;keep_transform=true;text=Keep transform",0,0);
- laShowItemFull(uil,c,pp,"_this_M_make_parent",0,"action=parent;keep_transform=false;text=Directly",0,0);
- }
- void laui_Unparent(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
- laColumn* c=laFirstColumn(uil);
- laShowItemFull(uil,c,pp,"_this_M_unparent",0,"action=unparent;keep_transform=true;text=Keep transform",0,0);
- laShowItemFull(uil,c,pp,"_this_M_unparent",0,"action=unparent;keep_transform=false;text=Directly",0,0);
- }
- STRUCTURE(MEDupVert){
- int oi; tnsMVert* nmv; tnsMVert* omv; int IsBorder;
- };
- STRUCTURE(MEDupEdge){
- int oi; tnsMEdge* nme; tnsMEdge* ome; int IsBorder;
- };
- STRUCTURE(MEDupFace){
- int oi; tnsMFace* nmf; tnsMFace* omf;
- };
- STRUCTURE(MExtrudeExtra){
- MEDupVert* dv; int nextv,maxv;
- MEDupEdge* de; int nexte,maxe;
- MEDupFace* df; int nextf,maxf;
- tnsMeshObject* mo;
- int RemoveOriginalFaces;
- };
- int la_IsSelectionBorderVertex(tnsMVert* mv){
- if(!mv->elink.pFirst)
- return 0;
- int NearSelected=0, NearUnselected=0;
- for(laListItemPointer* lip=mv->elink.pFirst;lip;lip=lip->pNext){
- tnsMEdge* me=lip->p; if(!(me->fl&&me->fr)) return 1;
- tnsMVert* av=tnsMMeshEdgeAnotherVert(me,mv);
- if(me->fl->flags&TNS_MESH_FLAG_SELECTED){ NearSelected=1; } else { return 1; }
- if(me->fr->flags&TNS_MESH_FLAG_SELECTED){ NearSelected=1; } else { return 1; }
- if(NearUnselected && NearSelected) return 1;
- }
- return 0;
- }
- int la_IsSelectionBorderEdge(tnsMEdge* me){
- if(me->fl&&me->fr){
- if ((me->fl->flags&TNS_MESH_FLAG_SELECTED) && (!(me->fr->flags&TNS_MESH_FLAG_SELECTED))||
- (me->fr->flags&TNS_MESH_FLAG_SELECTED) && (!(me->fl->flags&TNS_MESH_FLAG_SELECTED))) return 1;
- else return (me->fr->flags==me->fl->flags&&me->fl->flags==0);
- } return 1;
- }
- MExtrudeExtra* la_InitExtrude(tnsMeshObject* mo){
- MExtrudeExtra* ee=memAcquireSimple(sizeof(MExtrudeExtra));
- arrEnsureLength(&ee->dv, ee->nextv, &ee->maxv, sizeof(MEDupVert));
- arrEnsureLength(&ee->de, ee->nexte, &ee->maxe, sizeof(MEDupEdge));
- arrEnsureLength(&ee->df, ee->nextf, &ee->maxf, sizeof(MEDupFace));
- ee->mo=mo;
- return ee;
- }
- void la_ExtrudeMakeDuplication(MExtrudeExtra* ee){
- tnsMeshObject* mo=ee->mo;
- for(tnsMVert* mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){ if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue;
- arrEnsureLength(&ee->dv, ee->nextv, &ee->maxv, sizeof(MEDupVert));
- MEDupVert* dv=&ee->dv[ee->nextv];
- tnsMVert* nmv=tnsMMeshNewVert(mo); tnsVectorCopy3d(mv->p, &nmv->p); dv->oi=mv->i; mv->i=ee->nextv; dv->nmv=nmv; dv->omv=mv;
- dv->IsBorder=la_IsSelectionBorderVertex(mv);
- ee->nextv++;
- }
- for(tnsMEdge* me=mo->me.pFirst;me;me=me->Item.pNext){ if(!(me->flags&TNS_MESH_FLAG_SELECTED)) continue;
- arrEnsureLength(&ee->de, ee->nexte, &ee->maxe, sizeof(MEDupEdge));
- MEDupEdge* de=&ee->de[ee->nexte];
- tnsMEdge* nme=tnsMMeshNewEdge(mo); de->oi=me->i; me->i=ee->nexte; de->nme=nme; de->ome=me; de->IsBorder=la_IsSelectionBorderEdge(me);
- tnsMMeshEdgeAssignVerts(nme, ee->dv[me->vl->i].nmv, ee->dv[me->vr->i].nmv);
- if(de->IsBorder&&me->fl&&me->fr){ ee->RemoveOriginalFaces=1; }
- ee->nexte++;
- }
- for(tnsMFace* mf=mo->mf.pFirst;mf;mf=mf->Item.pNext){
- if(!(mf->flags&TNS_MESH_FLAG_SELECTED)) continue;
- arrEnsureLength(&ee->df, ee->nextf, &ee->maxf, sizeof(MEDupFace));
- MEDupFace* df=&ee->df[ee->nextf];
- tnsMFace* nmf=tnsMMeshNewFace(mo); df->oi=mf->i; mf->i=ee->nextf; df->nmf=nmf; df->omf=mf;
- for(laListItemPointer*lip=mf->l.pFirst;lip;lip=lip->pNext){
- tnsMEdge* ome=lip->p; tnsMMeshFaceAddEdge(nmf,ee->de[ome->i].nme);
- }
- ee->nextf++;
- }
- for(int i=0;i<ee->nextv;i++){ ee->dv[i].omv->i=ee->dv[i].oi; ee->dv[i].omv->flags&=(~TNS_MESH_FLAG_SELECTED); ee->dv[i].nmv->flags|=TNS_MESH_FLAG_SELECTED; }
- for(int i=0;i<ee->nexte;i++){ ee->de[i].ome->i=ee->de[i].oi; ee->de[i].ome->flags&=(~TNS_MESH_FLAG_SELECTED); ee->de[i].nme->flags|=TNS_MESH_FLAG_SELECTED; }
- for(int i=0;i<ee->nextf;i++){
- ee->df[i].omf->i=ee->df[i].oi;
- ee->df[i].omf->flags&=(~TNS_MESH_FLAG_SELECTED);
- ee->df[i].nmf->flags|=TNS_MESH_FLAG_SELECTED; }
- }
- void la_RemoveOriginalFaces(MExtrudeExtra* ee){
- tnsMeshObject* mo=ee->mo;
- if(ee->RemoveOriginalFaces){
- for(int i=0;i<ee->nextf;i++){ tnsMMeshRemoveFaceOnly(mo, ee->df[i].omf); }
- for(int i=0;i<ee->nexte;i++){ if(ee->de[i].IsBorder) continue; tnsMMeshRemoveEdgeFace(mo, ee->de[i].ome); }
- for(int i=0;i<ee->nextv;i++){ if(ee->dv[i].IsBorder) continue; tnsMMeshRemoveVertEdgeFace(mo, ee->dv[i].omv); }
- }
- }
- void la_ReconnectFaces(MExtrudeExtra* ee){
- tnsMeshObject* mo=ee->mo;
- for(int i=0;i<ee->nexte;i++){
- if(!ee->de[i].IsBorder) continue; MEDupEdge*de=&ee->de[i];
- tnsMMeshMakeFace4v(mo, de->ome->vl, de->ome->vr, de->nme->vr, de->nme->vl);
- }
- }
- void la_FinishExtrude(MExtrudeExtra* ee, int PushDifferences){
- tnsMMeshRefreshIndex(ee->mo);
- tnsInvalidateMeshBatch(ee->mo);
- if(PushDifferences){
- laRecordInstanceDifferences(ee->mo, "tns_mesh_object"); laPushDifferences("Extruded", TNS_HINT_GEOMETRY); laNotifyUsers("tns.world");
- }
- free(ee->dv); free(ee->de); free(ee->df); memFree(ee);
- }
- int OPINV_Extrude(laOperator *a, laEvent *e){
- 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; if(mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE) return 0;
- if(!tnsMMeshAnySelected(mo)) return LA_FINISHED;
- MExtrudeExtra* ee=la_InitExtrude(mo);
- la_ExtrudeMakeDuplication(ee);
-
- if(strSame(strGetArgumentString(a->ExtraInstructionsP,"duplicate_only"), "true")){
- la_FinishExtrude(ee, 1);
- if(la_InitTransform(a, e, LA_TRANSFORM_MODE_GRAB,0,0)) return LA_RUNNING; return LA_FINISHED;
- }
- la_RemoveOriginalFaces(ee);
- la_ReconnectFaces(ee);
- la_FinishExtrude(ee, 1);
- if(la_InitTransform(a, e, LA_TRANSFORM_MODE_GRAB,0,0)) return LA_RUNNING; return LA_FINISHED;
- return LA_FINISHED;
- }
- int la_EdgeShouldDeleteVert(tnsMVert* mv){
- if(!mv->elink.pFirst) return 0;
- int NearSelected=0, NearUnselected=0;
- for(laListItemPointer* lip=mv->elink.pFirst;lip;lip=lip->pNext){
- tnsMEdge* me=lip->p;
- tnsMVert* av=tnsMMeshEdgeAnotherVert(me,mv);
- if(av->flags&TNS_MESH_FLAG_SELECTED){ NearSelected=1; } else { NearUnselected=1; }
- if(NearUnselected && NearSelected) return 0;
- }
- if(NearSelected&&(!NearUnselected)) return 1; return 0;
- }
- int la_FaceShouldDeleteVert(tnsMVert* mv){
- if(!mv->elink.pFirst) return 0;
- int NearSelected=0, NearUnselected=0, IsBorder=0;
- for(laListItemPointer* lip=mv->elink.pFirst;lip;lip=lip->pNext){
- tnsMEdge* me=lip->p;
- if(!(me->fl&&me->fr)){ IsBorder=1; }
- if(me->fl){ if(me->fl->flags&TNS_MESH_FLAG_SELECTED){ NearSelected=1; } else { NearUnselected=1; } }
- if(me->fr){ if(me->fr->flags&TNS_MESH_FLAG_SELECTED){ NearSelected=1; } else { NearUnselected=1; } }
- if(NearUnselected && NearSelected) return 0;
- }
- if((!NearUnselected) && IsBorder) return 1;
- return 1;
- }
- int la_FaceShouldDeleteEdge(tnsMEdge* me){
- if(me->fl&&me->fr){
- if ((me->fl->flags&TNS_MESH_FLAG_SELECTED) && (!(me->fr->flags&TNS_MESH_FLAG_SELECTED))||
- (me->fr->flags&TNS_MESH_FLAG_SELECTED) && (!(me->fl->flags&TNS_MESH_FLAG_SELECTED))) return 0;
- else return (me->fr->flags==me->fl->flags&&me->fl->flags==1);
- }else{
- if(me->fl&&me->fl->flags&TNS_MESH_FLAG_SELECTED&&!me->fr) return 1;
- if(me->fr&&me->fr->flags&TNS_MESH_FLAG_SELECTED&&!me->fl) return 1;
- } return 0;
- }
- void la_DeleteVertices(tnsMeshObject* mo){
- tnsMVert* nextmv; for(tnsMVert*mv=mo->mv.pFirst;mv;mv=nextmv){ nextmv=mv->Item.pNext; if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue;
- tnsMMeshRemoveVertEdgeFace(mo, mv);
- }
- }
- void la_DeleteEdges(tnsMeshObject* mo){
- laListHandle lv={0};
- for(tnsMVert*mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){ if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue;
- if(la_EdgeShouldDeleteVert(mv)) lstAppendPointer(&lv,mv);
- }
- tnsMEdge* nextme; for(tnsMEdge*me=mo->me.pFirst;me;me=nextme){ nextme=me->Item.pNext; if(!(me->flags&TNS_MESH_FLAG_SELECTED)) continue;
- tnsMMeshRemoveEdgeFace(mo, me);
- }
- tnsMVert* mv; while(mv=lstPopPointer(&lv)){ tnsMMeshRemoveVertEdgeFace(mo,mv); }
- }
- void la_DeleteFaces(tnsMeshObject* mo, int OnlyFaces){
- laListHandle lv={0}, le={0};
- if(OnlyFaces){
- tnsMFace* nextmf; for(tnsMFace*mf=mo->mf.pFirst;mf;mf=nextmf){ nextmf=mf->Item.pNext; if(!(mf->flags&TNS_MESH_FLAG_SELECTED)) continue;
- tnsMMeshRemoveFaceOnly(mo, mf);
- }
- }else{
- for(tnsMVert*mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){ if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue;
- if(la_FaceShouldDeleteVert(mv)) lstAppendPointer(&lv,mv);
- }
- for(tnsMEdge*me=mo->me.pFirst;me;me=me->Item.pNext){ if(!(me->flags&TNS_MESH_FLAG_SELECTED)) continue;
- if(la_FaceShouldDeleteEdge(me)) lstAppendPointer(&le,me);
- }
- tnsMFace* nextmf; for(tnsMFace*mf=mo->mf.pFirst;mf;mf=nextmf){ nextmf=mf->Item.pNext; if(!(mf->flags&TNS_MESH_FLAG_SELECTED)) continue;
- tnsMMeshRemoveFaceOnly(mo, mf);
- }
- tnsMEdge* me; while(me=lstPopPointer(&le)){ tnsMMeshRemoveEdgeFace(mo,me); }
- tnsMVert* mv; while(mv=lstPopPointer(&lv)){ tnsMMeshRemoveVertEdgeFace(mo,mv); }
- }
- }
- int la_DeleteSelectedObjectsRecursive(tnsObject* root){
- int any=0; for(laListItemPointer* lip=root->ChildObjects.pFirst;lip;lip=lip->pNext){ if(!lip->p) continue;
- tnsObject* o=lip->p; la_DeleteSelectedObjectsRecursive(lip->p);
- if(o->Flags&TNS_OBJECT_FLAGS_SELECTED){ tnsDestroyObject(o); any++; }
- }
- return any;
- }
- int OPINV_Delete(laOperator *a, laEvent *e){
- 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; if(!mo) return 0;
-
- if(mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){
- if(la_DeleteSelectedObjectsRecursive(root)){
- laRecordInstanceDifferences(T->World, "tns_world"); laPushDifferences("Deleted objects", TNS_HINT_TRANSFORM); laNotifyUsers("tns.world");
- }
- }else{
- if(!tnsMMeshAnySelected(mo)) return LA_FINISHED;
- if(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"),"vertices")){
- la_DeleteVertices(mo);
- }elif(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"),"edges")){
- la_DeleteEdges(mo);
- }elif(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"),"faces")){
- la_DeleteFaces(mo,0);
- }elif(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"),"only_faces")){
- la_DeleteFaces(mo,1);
- }else{
- laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
- return LA_RUNNING;
- }
- tnsMMeshDeselectAll(mo);
- tnsMMeshRefreshIndex(mo);
- tnsInvalidateMeshBatch(mo);
- laRecordInstanceDifferences(mo, "tns_mesh_object"); laPushDifferences("Deleted primitives", TNS_HINT_GEOMETRY); laNotifyUsers("tns.world");
- }
- return LA_FINISHED;
- }
- void laui_Delete(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
- laColumn* c=laFirstColumn(uil);
- laShowItemFull(uil,c,pp,"_this_M_delete",0,"mode=vertices;text=Vertices",0,0);
- laShowItemFull(uil,c,pp,"_this_M_delete",0,"mode=edges;text=Edges",0,0);
- laShowItemFull(uil,c,pp,"_this_M_delete",0,"mode=faces;text=Faces",0,0);
- laShowItemFull(uil,c,pp,"_this_M_delete",0,"mode=only_faces;text=Only Faces",0,0);
- }
- STRUCTURE(MIslandInfo){
- laListItem Item;
- laListHandle v,e,f;int numv,nume,numf;
- int Paired,HasBranches;
- };
- STRUCTURE(MMakeData){
- laListHandle Islands; int NumIslands;
- };
- #define M_SHOULD_INCL_PRIM(m) \
- ((!(m->flags&TNS_MESH_FLAG_PICKED)) && (m->flags&TNS_MESH_FLAG_SELECTED))
- #define M_SHOULD_USE_OE(oe,sf) \
- (((!oe->fl)&&((!sf)||(oe->fr!=sf)))||((!oe->fr)&&((!sf)||(oe->fl!=sf))))
- MIslandInfo* la_NewMIsland(MMakeData* md){ MIslandInfo* ii=memAcquireSimple(sizeof(MIslandInfo)); lstAppendItem(&md->Islands, ii); md->NumIslands++; return ii; }
- void la_FillIslandFromVert(MIslandInfo* ii, tnsMVert* mv, int SelectMode){
- mv->flags|=TNS_MESH_FLAG_PICKED; lstAppendPointer(&ii->v,mv); ii->numv++; int connections=0;
- for(laListItemPointer* lip=mv->elink.pFirst;lip;lip=lip->pNext){ tnsMEdge* oe=lip->p; tnsMVert* ov=tnsMMeshEdgeAnotherVert(oe,mv);
- if(ov->flags&TNS_MESH_FLAG_SELECTED) connections++; else continue;
- if(SelectMode==LA_CANVAS_SELECT_MODE_EDGES){ if(!(oe->flags&TNS_MESH_FLAG_SELECTED)) continue; }
- if(M_SHOULD_INCL_PRIM(ov)){ la_FillIslandFromVert(ii,ov,SelectMode); } else { continue; }
- if(M_SHOULD_INCL_PRIM(oe)){ lstAppendPointer(&ii->e,oe); ii->nume++; oe->flags|=TNS_MESH_FLAG_PICKED; }
- if(oe->fl&&M_SHOULD_INCL_PRIM(oe->fl)){ lstAppendPointer(&ii->f,oe->fl); ii->numf++; oe->fl->flags|=TNS_MESH_FLAG_PICKED; }
- if(oe->fr&&M_SHOULD_INCL_PRIM(oe->fr)){ lstAppendPointer(&ii->f,oe->fr); ii->numf++; oe->fr->flags|=TNS_MESH_FLAG_PICKED; }
- }
- if(connections>2) ii->HasBranches=1;
- }
- void la_GetSelectionIslands(tnsMeshObject* mo, MMakeData* md, int SelectMode){
- tnsMMeshClearExtraFlags(mo);
- for(tnsMVert* mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){
- if(M_SHOULD_INCL_PRIM(mv)){ MIslandInfo* ii=la_NewMIsland(md); la_FillIslandFromVert(ii,mv,SelectMode); }
- }
- }
- void la_ClearIslands(MMakeData* md){ MIslandInfo* ii; while(ii=lstPopItem(&md->Islands)){ while(lstPopPointer(&ii->v)); memFree(ii); } }
- tnsMFace* la_MakeFacesFrom1Vert(tnsMeshObject* mo, tnsMVert* mv){
- tnsMEdge* oe1=0,*oe2=0; tnsMVert* ov1,*ov2;
- for(laListItemPointer* lip=mv->elink.pFirst;lip;lip=lip->pNext){
- tnsMEdge* oe=lip->p; if(oe->flags&TNS_MESH_FLAG_SELECTED) continue; if((!oe->fl)||(!oe->fr)){ if(!oe1)oe1=oe;elif(!oe2)oe2=oe;else return 0; /* more than 2 empty edges connected */ }
- } if(!oe1||!oe2) return 0;
- ov1=tnsMMeshEdgeAnotherVert(oe1,mv); ov2=tnsMMeshEdgeAnotherVert(oe2,mv);
- laListHandle vl={0}; lstAppendPointer(&vl,ov1); lstAppendPointer(&vl,mv); lstAppendPointer(&vl,ov2);
- tnsMFace* f=tnsMMeshMakeFaceN(mo, 3, &vl, 0);
- ov1->flags|=TNS_MESH_FLAG_SELECTED;ov2->flags|=TNS_MESH_FLAG_SELECTED; mv->flags&=(~TNS_MESH_FLAG_SELECTED);
- tnsMMeshEnsureSelectionFromVerts(mo);
- while(lstPopPointer(&vl)); return f;
- }
- tnsMFace* la_MakeFacesFrom2Verts(tnsMeshObject* mo, tnsMVert* mv1, tnsMVert* mv2){
- tnsMEdge* oe1=0,*oe2=0; tnsMVert* ov1,*ov2; tnsMFace* sf=0;
- tnsMEdge* se=tnsMMeshVertsShareEdge(mv1,mv2); if(se->fl && se->fr) return 0; sf=se->fl?se->fl:se->fr;
- for(laListItemPointer* lip=mv1->elink.pFirst;lip;lip=lip->pNext){
- tnsMEdge* oe=lip->p; if(oe->flags&TNS_MESH_FLAG_SELECTED) continue; if(M_SHOULD_USE_OE(oe,sf)){ if(!oe1)oe1=oe;else return 0; /* more than 1 empty edge connected */ }
- }
- for(laListItemPointer* lip=mv2->elink.pFirst;lip;lip=lip->pNext){
- tnsMEdge* oe=lip->p; if(oe->flags&TNS_MESH_FLAG_SELECTED) continue; if(M_SHOULD_USE_OE(oe,sf)){ if(!oe2)oe2=oe;else return 0; /* more than 1 empty edge connected */ }
- }
- if(!oe1||!oe2) return 0;
- ov1=tnsMMeshEdgeAnotherVert(oe1,mv1); ov2=tnsMMeshEdgeAnotherVert(oe2,mv2);
- ov1->flags|=TNS_MESH_FLAG_SELECTED;ov2->flags|=TNS_MESH_FLAG_SELECTED; mv1->flags&=(~TNS_MESH_FLAG_SELECTED);mv2->flags&=(~TNS_MESH_FLAG_SELECTED);
- laListHandle vl={0}; int vcount=3;
- lstAppendPointer(&vl,ov1); lstAppendPointer(&vl,mv1); lstAppendPointer(&vl,mv2); if(ov2!=ov1){ lstAppendPointer(&vl,ov2); vcount=4; }
- tnsMFace* f=tnsMMeshMakeFaceN(mo, vcount, &vl, 0); tnsMMeshEnsureSelectionFromVerts(mo);
- while(lstPopPointer(&vl)); return f;
- }
- int la_IsEndingVert(tnsMVert* mv){
- int sel=0; for(laListItemPointer*lip=mv->elink.pFirst;lip;lip=lip->pNext){ tnsMEdge* me=lip->p;
- if(tnsMMeshEdgeAnotherVert(me,mv)->flags&TNS_MESH_FLAG_SELECTED){ sel++; if(sel>1) return 0; }
- }
- if(sel==1) return 1; return 0;
- }
- void la_EnsureIslandVertsSequence(MIslandInfo* ii){
- laListHandle l={0}; tnsMVert* startv=((laListItemPointer*)ii->v.pFirst)->p; laListItemPointer* nextlip;
- for(laListItemPointer*lip=ii->v.pFirst;lip;lip=lip->pNext){ if(la_IsEndingVert(lip->p)){ startv=lip->p; break; } } // otherwise a loop, doesn't matter.
- lstRemovePointer(&ii->v, startv); lstAppendPointer(&l, startv);
- while(ii->v.pFirst){
- for(laListItemPointer*lip=ii->v.pFirst;lip;lip=lip->pNext){ nextlip=lip->pNext;
- if(tnsMMeshVertsShareEdge(startv, lip->p)){ startv=lip->p; lstRemoveItem(&ii->v,lip); lstAppendItem(&l, lip); break; }
- }
- }
- memcpy(&ii->v, &l, sizeof(laListHandle));
- }
- MIslandInfo* la_GetNeighborIsland(tnsMVert* from, MMakeData* md){
- int found=0; real dist=1e10; MIslandInfo* rii=0; for(MIslandInfo* ii=md->Islands.pFirst;ii;ii=ii->Item.pNext){ if(ii->Paired) continue;
- found=1; tnsMVert* mv1=((laListItemPointer*)ii->v.pFirst)->p,*mv2=((laListItemPointer*)ii->v.pLast)->p;
- real d1=tnsDist3dv(mv1->p, from->p),d2=tnsDist3dv(mv2->p, from->p);
- if(d2<d1 && d2<dist){ lstReverse(&ii->v); } if(d1<dist || d2<dist){ rii=ii; }
- }
- if(rii) rii->Paired=1;
- return rii;
- }
- int la_MakeFacesFromIslands(tnsMeshObject* mo, MMakeData* md){
- int success=0;
- if(!md->Islands.pFirst) return 0;
- if(md->Islands.pFirst==md->Islands.pLast){
- MIslandInfo* ii=md->Islands.pFirst; if(ii->HasBranches) return 0;
- if(ii->numv==1){ laListItemPointer*lip=ii->v.pFirst; if(la_MakeFacesFrom1Vert(mo,lip->p)) success++; }
- elif(ii->numv==2){ laListItemPointer*lip=ii->v.pFirst,*lip2=ii->v.pLast; if(la_MakeFacesFrom2Verts(mo,lip->p, lip2->p)) success++; }
- else{ la_EnsureIslandVertsSequence(ii); if(tnsMMeshMakeFaceN(mo, ii->numv, &ii->v, 0)) success++; }
- }else{
- for(MIslandInfo* ii=md->Islands.pFirst;ii;ii=ii->Item.pNext){ if(ii->HasBranches) return 0; la_EnsureIslandVertsSequence(ii); }
- laListHandle final={0}; int vcount=0;
- MIslandInfo* ii=md->Islands.pFirst; ii->Paired=1; for(laListItemPointer* lip=ii->v.pFirst;lip;lip=lip->pNext){ lstAppendPointer(&final, lip->p); vcount++; }
- while((ii=la_GetNeighborIsland(((laListItemPointer*)ii->v.pLast)->p, md))){
- for(laListItemPointer* lip=ii->v.pFirst;lip;lip=lip->pNext){ lstAppendPointer(&final, lip->p); vcount++; }
- }
- tnsMEdge* fallback_e=0;
- if(tnsMMeshMakeFaceN(mo,vcount,&final, &fallback_e) || fallback_e) success++;
- while(lstPopPointer(&final));
- }
- return success;
- }
- int OPINV_Make(laOperator *a, laEvent *e){
- 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;
-
- if(!mo||mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- MMakeData md={0};
- la_GetSelectionIslands(mo,&md,ex->SelectMode);
- int success=la_MakeFacesFromIslands(mo,&md); if(success){ tnsMMeshCalculateNormal(mo); }
- la_ClearIslands(&md);
- tnsMMeshRefreshIndex(mo);
- tnsMMeshEnsureSelection(mo,ex->SelectMode);
- tnsInvalidateMeshBatch(mo);
- if(laRecordInstanceDifferences(mo, "tns_mesh_object")) laPushDifferences("Make primitives", TNS_HINT_GEOMETRY);
- laNotifyUsers("tns.world");
-
- return LA_FINISHED;
- }
- int OPINV_Subdiv(laOperator *a, laEvent *e){
- 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;
-
- if(mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- laListHandle pending={0}; for(tnsMEdge* me=mo->me.pFirst;me;me=me->Item.pNext){ if(me->flags&TNS_MESH_FLAG_SELECTED) lstAppendPointer(&pending, me); }
- if(!pending.pFirst) return LA_FINISHED;
- tnsMEdge* me; while(me=lstPopPointer(&pending)){ tnsMVert* mv=tnsMMeshEdgeInsertVertAt(mo,me,0.5,0,0,0); mv->flags|=TNS_MESH_FLAG_SELECTED; }
- tnsMMeshRefreshIndex(mo);
- tnsMMeshEnsureSelection(mo,ex->SelectMode);
- tnsInvalidateMeshBatch(mo);
- if(laRecordInstanceDifferences(mo, "tns_mesh_object")) laPushDifferences("Subdivide edges", TNS_HINT_GEOMETRY);
- laNotifyUsers("tns.world");
-
- return LA_FINISHED;
- }
- #define LA_ADD_CTX_OBJECT 0
- #define LA_ADD_CTX_MESH 1
- STRUCTURE(laObjectAddData){
- int Context;
- };
- int OPINV_Add(laOperator *a, laEvent *e){
- 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; int ran=0; tnsObject* no=0;
- laObjectAddData *ad=memAcquire(sizeof(laObjectAddData));a->CustomData=ad;
- char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
- if((!mo) || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){ ad->Context=LA_ADD_CTX_OBJECT;
- if(strSame(str,"PLANE")){ tnsDeselectAllObjects(root);
- no=tnsCreateMeshPlane(root, "Plane",0,0,0,1); no->Flags|=TNS_OBJECT_FLAGS_SELECTED; memAssignRef(root,&root->Active,no); ran=1; }
- 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; }
- 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"); }
- }else{ ad->Context=LA_ADD_CTX_MESH;
- if(strSame(str,"PLANE")){
- tnsMMeshDeselectAll(mo); tnsAddMMeshPlane(mo, 1); tnsMMeshEnsureSelection(mo,ex->SelectMode); 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){
- tnsMMeshRefreshIndex(mo); tnsInvalidateMeshBatch(mo);
- laRecordInstanceDifferences(mo, "tns_mesh_object"); laPushDifferences("Add primitives", TNS_HINT_GEOMETRY); laNotifyUsers("tns.world");
- }
- }
- return LA_FINISHED;
- }
- void laui_Add(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
- laColumn* c=laFirstColumn(uil);
- laUiItem* b=laOnConditionThat(uil,c,laEqual(laPropExpression(actinst,"context"),laIntExpression(LA_ADD_CTX_OBJECT)));{
- laShowLabel(uil,c,"Empty",0,0)->Flags|=LA_TEXT_MONO|LA_UI_FLAGS_DISABLED;
- laShowItemFull(uil,c,pp,"_this_M_add",0,"mode=INSTANCER;text=Instancer",0,0);
- }laEndCondition(uil,b);
- laShowLabel(uil,c,"Primitives",0,0)->Flags|=LA_TEXT_MONO|LA_UI_FLAGS_DISABLED;
- laShowItemFull(uil,c,pp,"_this_M_add",0,"mode=PLANE;text=Plane",0,0);
- }
- int OPINV_Separate(laOperator *a, laEvent *e){
- 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 LA_CANCELED;
- tnsMeshObject* mo=root->Active; int ran=0;
-
- if(mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){
- return LA_CANCELED;
- }
- if(!tnsMMeshAnySelected(mo)) return LA_CANCELED;
- MExtrudeExtra* ee=la_InitExtrude(mo);
- la_ExtrudeMakeDuplication(ee);
- ee->RemoveOriginalFaces=1;la_RemoveOriginalFaces(ee);
- tnsMeshObject* no=tnsCreateMeshEmpty(mo->Base.ParentObject?mo->Base.ParentObject:mo->Base.InRoot, mo->Base.Name->Ptr, 0,0,0);
- tnsCopyObjectTransformationsLocal(no,mo);
- no->Mode=TNS_MESH_EDIT_MODE;
- tnsMVert* nmv; for(tnsMVert* mv=mo->mv.pFirst;mv;mv=nmv){ nmv=mv->Item.pNext; if(!(mv->flags&TNS_MESH_FLAG_SELECTED))continue;
- lstRemoveItem(&mo->mv, mv); lstAppendItem(&no->mv, mv); no->totmv++; mo->totmv--; }
- tnsMEdge* nme; for(tnsMEdge* me=mo->me.pFirst;me;me=nme){ nme=me->Item.pNext; if(!(me->flags&TNS_MESH_FLAG_SELECTED))continue;
- lstRemoveItem(&mo->me, me); lstAppendItem(&no->me, me); no->totme++; mo->totme--; }
- tnsMFace* nmf; for(tnsMFace* mf=mo->mf.pFirst;mf;mf=nmf){ nmf=mf->Item.pNext; if(!(mf->flags&TNS_MESH_FLAG_SELECTED))continue;
- lstRemoveItem(&mo->mf, mf); lstAppendItem(&no->mf, mf); no->totmf++; mo->totmf--; }
- tnsMMeshRefreshIndex(no); tnsMeshLeaveEditMode(no);
- la_FinishExtrude(ee, 0);
- tnsMMeshRefreshIndex(mo); tnsInvalidateMeshBatch(mo);
- laRecordAndPush(0,"tns.world","Separate mesh parts",TNS_HINT_GEOMETRY); laNotifyUsers("tns.world");
-
- return LA_FINISHED;
- }
- void la_PopulateSelectedMeshObjects(tnsObject* root, laListHandle* l){
- if(root->Type==TNS_OBJECT_MESH && root->Flags&TNS_OBJECT_FLAGS_SELECTED){ lstAppendPointer(l,root); }
- for(laListItemPointer* lip=root->ChildObjects.pFirst;lip;lip=lip->pNext){
- la_PopulateSelectedMeshObjects(lip->p, l);
- }
- }
- int OPINV_Combine(laOperator *a, laEvent *e){
- 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 LA_CANCELED;
- tnsMeshObject* mo=root->Active; int ran=0;
-
- if(!mo || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode==TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- laListHandle pending={0}; la_PopulateSelectedMeshObjects(root,&pending);
- tnsMeshObject* o; while(o=lstPopPointer(&pending)){ if(o==mo || o->Mode==TNS_MESH_EDIT_MODE) continue;
- if(tnsMergeMeshObjects(mo, o)) ran++;
- }
- if(ran){
- tnsMMeshRefreshIndex(mo); tnsInvalidateMeshBatch(mo);
- laRecordAndPush(0,"tns.world","Merge mesh objects",TNS_HINT_GEOMETRY); laNotifyUsers("tns.world");
- }
-
- return LA_FINISHED;
- }
- int OPINV_Duplicate(laOperator *a, laEvent *e){
- 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 LA_CANCELED;
- tnsMeshObject* mo=root->Active; int ran=0;
-
- if(!mo || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode==TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- laListHandle pending={0}; la_PopulateSelectedMeshObjects(root,&pending);
- tnsMeshObject* o; tnsMeshObject* no; laListItemPointer* lip;
- for(lip=pending.pFirst;lip;lip=lip->pNext){ o=lip->p; o->Base.EditDuplicateTemp=0; if (o->Mode == TNS_MESH_EDIT_MODE) continue;
- if (no = tnsDuplicateMeshObject(o)){ o->Base.EditDuplicateTemp=no;
- no->Base.Flags |= TNS_OBJECT_FLAGS_SELECTED; o->Base.Flags &= (~TNS_OBJECT_FLAGS_SELECTED);
- if (mo == o) { memAssignRef(root, &root->Active, no); } ran++;
- }
- }
- for (lip = pending.pFirst;lip;lip=lip->pNext){ o=lip->p; no = o->Base.EditDuplicateTemp;
- tnsObject* NewParent=o->Base.ParentObject?o->Base.ParentObject->EditDuplicateTemp:0;
- if(NewParent){ tnsUnparentObject(no,1); tnsParentObject(no,NewParent,1); }
- }
- while(o=lstPopPointer(&pending)){ o->Base.EditDuplicateTemp=0; }
-
- if(ran){
- laRecordAndPush(0,"tns.world","Merge mesh objects",TNS_HINT_GEOMETRY); laNotifyUsers("tns.world");
- if(la_InitTransform(a,e,LA_TRANSFORM_MODE_GRAB,0,0)) return LA_RUNNING; return LA_FINISHED;
- }
-
- return LA_FINISHED;
- }
- int OPINV_RecalculateNormals(laOperator *a, laEvent *e){
- 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 LA_CANCELED;
- tnsMeshObject* mo=root->Active; int ran=0;
-
- if(!mo || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- ran=tnsMMeshCalculateNormal(mo);
-
- if(ran){ tnsInvalidateMeshBatch(mo); laRecordAndPush(0,"tns.world","Recalculate Normals",TNS_HINT_GEOMETRY); laNotifyUsers("tns.world"); }
-
- return LA_FINISHED;
- }
- STRUCTURE(MKnifeElement){
- laListItem Item;
- void* p;
- int Type;
- };
- void la_KnifeUpdateToolBatch(MSelectExtra* se,tnsMeshObject* o){
- if(o->ExtraBatch) tnsDeleteBatch(o->ExtraBatch); o->ExtraBatch=0;
- int count=lstCountElements(&se->KnifeElements); if((!count) && (!se->PendingElem)) return;
- float* points=calloc((count+1)*3,sizeof(real));
- float* p=points; real tmp[3],trans[4];
- for(MKnifeElement* ke=se->KnifeElements.pFirst;ke;ke=ke->Item.pNext){
- if(ke->Type==TNS_MMESH_EDGE_BIT){ tnsMEdge* me=ke->p; tnsVectorSet3v(tmp,me->vl->p); tnsVectorAccum3d(tmp,me->vr->p);
- tnsVectorMultiSelf3d(tmp,0.5); tnsApplyTransform43d(trans,o->Base.GlobalTransform,tmp); tnsVectorSet3v(p,trans); }
- else{ tnsMVert* mv=ke->p; tnsApplyTransform43d(trans,o->Base.GlobalTransform,mv->p); tnsVectorSet3v(p,trans); }
- p+=3;
- }
- if(se->PendingElem){
- if(se->PendingElemType==TNS_MMESH_EDGE_BIT){ tnsMEdge* me=se->PendingElem; tnsVectorSet3v(tmp,me->vl->p); tnsVectorAccum3d(tmp,me->vr->p);
- tnsVectorMultiSelf3d(tmp,0.5); tnsApplyTransform43d(trans,o->Base.GlobalTransform,tmp); tnsVectorSet3v(p,trans); }
- else{ tnsMVert* mv=se->PendingElem; tnsApplyTransform43d(trans,o->Base.GlobalTransform,mv->p); tnsVectorSet3v(p,trans); }
- }elif(count){
- tnsVectorSet3v(p,p-3);
- }
- uint32_t elem=count;
- tnsBatch* batch=tnsCreateBatch(count+1,3,points,0,0,0,0); tnsBatchCommand*c;
- c=tnsCreateCommand(batch, "hovering_point", 1, 3, GL_POINTS, &elem, 0);
- tnsCommandUseUniformColor(c,laAccentColor(LA_BT_SVERTEX));
- tnsCommandUseWidth(c, 8);
- if(count){
- c=tnsCreateCommand(batch, "edges", count+(se->IsLoop?0:1), 3, se->IsLoop?GL_LINE_LOOP:GL_LINE_STRIP, 0, 0);
- tnsCommandUseUniformColor(c,laAccentColor(LA_BT_NORMAL));
- tnsCommandUseWidth(c, 2);
- c=tnsCreateCommand(batch, "points", count, 3, GL_POINTS, 0, 0);
- tnsCommandUseUniformColor(c,laAccentColor(LA_BT_NORMAL));
- tnsCommandUseWidth(c, 6);
- }
- o->ExtraBatch=batch;
- free(points);
- }
- int la_KnifeIsDuplicated(MSelectExtra* se, void* ref){
- for(MKnifeElement* ke=se->KnifeElements.pFirst;ke;ke=ke->Item.pNext){
- if(ke->Type==TNS_MMESH_EDGE_BIT && ke->p==ref){ return 1; }
- }
- return 0;
- }
- void la_KnifeAppendCut(MSelectExtra* se){
- MKnifeElement* ke=lstAppendPointerSized(&se->KnifeElements,se->PendingElem,sizeof(MKnifeElement));
- ke->Type=se->PendingElemType;
- }
- int la_KnifeRegisterCuts(MSelectExtra* se, tnsMeshObject* mo, int TryClose){
- if(!mo || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE) return 0;
- if(!se->KnifeElements.pFirst) return 0;
- tnsMVert* lastv=0,*newv=0,*firstv=0; tnsMEdge* newme=0; int changed=0; tnsMFace* mf=0;
- for(MKnifeElement* ke=se->KnifeElements.pFirst;ke;ke=ke->Item.pNext){
- if(ke->Type==TNS_MMESH_EDGE_BIT){
- newv=tnsMMeshEdgeInsertVertAt(mo,ke->p,0.5,0,0,0); changed=1;
- }
- else{ newv=ke->p; }
- if(lastv){ if(tnsMMeshVertsShareFace(lastv,newv)) newme=tnsMMeshMakeEdge(mo, lastv, newv); changed=1; }
- lastv=newv; if(!firstv) firstv=newv; newv->flags|=TNS_MESH_FLAG_SELECTED;
- if(newme){ newme->flags|=TNS_MESH_FLAG_SELECTED; }
- }
- if(TryClose){ if((mf=tnsMMeshVertsShareFace(lastv,firstv))&&mf->looplen==6) newme=tnsMMeshMakeEdge(mo, lastv, firstv); changed=1; }
- if(changed){ tnsMMeshRefreshIndex(mo); tnsMMeshCalculateNormal(mo); }
- return changed;
- }
- void la_KnifeFinish(MSelectExtra* se, tnsMeshObject*o){
- if(o->ExtraBatch) tnsDeleteBatch(o->ExtraBatch); o->ExtraBatch=0;
- while(lstPopPointer(&se->KnifeElements));
- la_FreeSelectData(se->sd); memFree(se);
- }
- void la_KnifeRefreshLoopCuts(MSelectExtra* se, tnsObject* o,tnsMEdge* me){
- if(!me) return;
- tnsMMeshClearExtraFlags(o);
- laListHandle lst={0}; lstAppendPointer(&lst,me); me->flags|=TNS_MESH_FLAG_PICKED;
- tnsMMeshExpandBandList(o, me, &lst);
- if(lst.pFirst==lst.pLast){ while(lstPopPointer(&lst)); return; }
- tnsMEdge* mme; while((mme=lstPopPointer(&lst))){
- MKnifeElement* ke=lstAppendPointerSized(&se->KnifeElements,mme,sizeof(MKnifeElement));
- ke->Type=TNS_MMESH_EDGE_BIT;
- }
- }
- void la_KnifeSortLoopCuts(MSelectExtra* se){
- laListHandle lst={0};MKnifeElement* ke=se->KnifeElements.pFirst,*NextKe;
- if(!ke) return;
- lstRemoveItem(&se->KnifeElements,ke); lstAppendItem(&lst,ke);
- for(ke=se->KnifeElements.pFirst;ke;ke=NextKe){
- NextKe=ke->Item.pNext; tnsMEdge* me=ke->p,*firste=((MKnifeElement*)lst.pFirst)->p,*laste=((MKnifeElement*)lst.pLast)->p;
- if(tnsMMeshEdgeShareFace(me,firste) && (!tnsMMeshEdgeShareVert(me,firste))){
- lstRemoveItem(&se->KnifeElements,ke); lstPushItem(&lst,ke); ke=se->KnifeElements.pFirst; continue; }
- if(tnsMMeshEdgeShareFace(me,laste) && (!tnsMMeshEdgeShareVert(me,laste))){
- lstRemoveItem(&se->KnifeElements,ke); lstAppendItem(&lst,ke); ke=se->KnifeElements.pFirst; continue; }
- }
- if(se->KnifeElements.pFirst){ /* something went wrong */ while(lstPopPointer(&se->KnifeElements)); while(lstPopPointer(&lst)); }
- se->KnifeElements.pFirst=lst.pFirst; se->KnifeElements.pLast=lst.pLast;
- }
- int OPINV_Knife(laOperator *a, laEvent *e){
- 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 LA_CANCELED;
- tnsMeshObject* mo=root->Active; int ran=0;
-
- if(!mo || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- MSelectExtra* se=memAcquire(sizeof(MSelectExtra));
- MSelectData* sd=la_InitSelectData(ex->OffScr->pColor[0]->Width, ex->OffScr->pColor[0]->Height, c);
- a->CustomData=se; se->sd=sd; se->root=root;
- int SelectMode=LA_CANVAS_SELECT_MODE_KNIFE;
- if(strSame(strGetArgumentString(a->ExtraInstructionsP, "mode"), "loop_cut")){
- se->IsLoop=1; SelectMode=LA_CANVAS_SELECT_MODE_EDGES; }
- la_PopulateSelectDataPrimitives(sd,mo,c,SelectMode,ex->SelectThrough);
- if(se->IsLoop){ strSafePrint(&a->RuntimeHint,"◧ Cut ◨ Cancel"); }
- else{ strSafePrint(&a->RuntimeHint,"◧ Place Cut ◨ Cancel ⮨ Confirm"); }
- return LA_RUNNING;
- }
- int OPMOD_Knife(laOperator *a, laEvent *e){
- if(!a->This || !a->This->EndInstance || !a->CustomData){ 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;
- MSelectExtra* se=a->CustomData;
- tnsMeshObject* mo=root->Active;
- int changed=0;
- if(e->Type==LA_R_MOUSE_DOWN || (e->Type == LA_KEY_DOWN && e->key==LA_KEY_ESCAPE)){
- la_KnifeFinish(se,mo); laNotifyUsers("tns.world"); return LA_FINISHED;
- }
- if(e->Type&LA_MOUSE_EVENT){
- int elemtype,id=la_SelectGetClosest(se->sd, e->x-ui->L, e->y-ui->U, LA_RH,&elemtype)-1;
- void* p=la_SelectGetRef(se->sd,id,elemtype);
- if(se->IsLoop){
- if(se->PendingElem!=p){ changed=1; while(lstPopPointer(&se->KnifeElements));
- se->PendingElem=p; la_KnifeRefreshLoopCuts(se, mo, se->PendingElem);
- la_KnifeSortLoopCuts(se);
- }
- }else{
- if(la_KnifeIsDuplicated(se,p)) p=0;
- if(se->PendingElem!=p){ changed=1; }
- se->PendingElem=p; se->PendingElemType=elemtype;
- if(e->Type==LA_L_MOUSE_DOWN && p){ la_KnifeAppendCut(se); changed=1; }
- }
- }
- if((e->Type==LA_KEY_DOWN && e->key==LA_KEY_ENTER) || (se->IsLoop && e->Type==LA_L_MOUSE_DOWN)){
- if(la_KnifeRegisterCuts(se,mo,se->IsLoop)){ tnsMMeshEnsureSelection(mo,ex->SelectMode);
- tnsInvalidateMeshBatch(mo); laNotifyUsers("tns.world");
- laRecordAndPush(0,"tns.world",se->IsLoop?"Loop Cut":"Knife Cut",TNS_HINT_GEOMETRY);
- }
- la_KnifeFinish(se,mo); return LA_FINISHED;
- }
-
- if(changed){
- la_KnifeUpdateToolBatch(se,mo); laRedrawCurrentPanel();
- }
-
- return LA_RUNNING;
- }
- #define LA_MERGE_MODE_CENTER 0
- #define LA_MERGE_MODE_FIRST 1
- #define LA_MERGE_MODE_LAST 2
- int la_MergeGetCenter(tnsMeshObject* mo, int SelectMode, int MergeMode, real* center){
- real pos[3]={0},tmp[3]={0}; int count=0;
- tnsMVert* usev=0; tnsMEdge* usee=0;
- if(MergeMode!=LA_MERGE_MODE_CENTER){
- if(MergeMode==LA_MERGE_MODE_FIRST){ usev=mo->FirstSelectV; usee=mo->FirstSelectE; }
- elif(MergeMode==LA_MERGE_MODE_LAST){ usev=mo->LastSelectV; usee=mo->LastSelectE; }
- if(SelectMode==LA_CANVAS_SELECT_MODE_VERTS && usev){ tnsVectorCopy3d(usev->p,center); return 1; }
- elif(SelectMode==LA_CANVAS_SELECT_MODE_EDGES && usee){
- tnsVectorAccum3d(pos,usee->vl->p);tnsVectorAccum3d(pos,usee->vr->p);
- tnsVectorMultiSelf3d(pos,0.5f); tnsVectorCopy3d(pos,center); return 1;
- }
- }
- for(tnsMVert* mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){ if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue;
- tnsVectorAccum3d(pos,mv->p); count++;
- }
- if(!count) return 0;
- tnsVectorMultiSelf3d(pos,1.0f/count); tnsVectorCopy3d(pos,center);
- return 1;
- }
- void la_MergeSelected(tnsMeshObject* mo, real* center, int* count_success, int* count_fail){
- tnsMVert* fmv=0,*NextMv=0; int success=0,fail=0,has_success=0;
- do{ fail=0; has_success=0;
- for(tnsMVert* mv=mo->mv.pFirst;mv;mv=NextMv){ NextMv=mv->Item.pNext;
- if((!(mv->flags&TNS_MESH_FLAG_SELECTED))||mv==fmv) continue; if(!fmv){ fmv=mv; success++; continue; }
- if(tnsMMeshMergeVerts(mo,fmv,mv)){ success++; has_success=1; }else{ fail++; }
- }
- }while(has_success&&fail);
- if(count_success){ *count_success=success; } if(count_fail){ *count_fail=fail; }
- if(!fmv) return; tnsVectorCopy3d(center,fmv->p);
- tnsMMeshRefreshIndex(mo);
- }
- int OPINV_Merge(laOperator *a, laEvent *e){
- 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 LA_CANCELED;
- tnsMeshObject* mo=root->Active; int ran=0;
-
- if(!mo || mo->Base.Type!=TNS_OBJECT_MESH || mo->Mode!=TNS_MESH_EDIT_MODE){ return LA_CANCELED; }
- char* arg=strGetArgumentString(a->ExtraInstructionsP, "towards");
- if(arg){
- int MergeMode=LA_MERGE_MODE_CENTER; real center[3];
- if(strSame(arg,"FIRST")){ MergeMode=LA_MERGE_MODE_FIRST; }
- elif(strSame(arg,"LAST")){ MergeMode=LA_MERGE_MODE_LAST; }
- if(!(la_MergeGetCenter(mo,ex->SelectMode,MergeMode,center))){
- laEnableMessagePanel(a, 0, "Can't perform merging:", "No vertices selected.", e->x, e->y, 0, e);
- return LA_FINISHED;
- }
- int success,fail;
- la_MergeSelected(mo,center,&success,&fail); //printf("succeeded: %d failed:%d\n",success,fail);
- if(fail){
- char* msg[256]; sprintf(msg,"Succeeded: %d vertices, failed: %d vertices.",success,fail);
- laEnableMessagePanel(a, 0, "Merging partially succeeded.", msg, e->x, e->y, 0, e);
- }
- if(success){
- tnsMMeshEnsureSelection(mo,ex->SelectMode); tnsInvalidateMeshBatch(mo); laNotifyUsers("tns.world");
- laRecordAndPush(0,"tns.world","Merge vertices",TNS_HINT_GEOMETRY);
- }
- }else{
- laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e); return LA_RUNNING;
- }
- return LA_FINISHED;
- }
- void laui_Merge(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context){
- laColumn* c=laFirstColumn(uil);
- laShowItemFull(uil,c,pp,"_this_M_merge",0,"towards=CENTER;text=Center",0,0);
- laShowItemFull(uil,c,pp,"_this_M_merge",0,"towards=FIRST;text=First",0,0);
- laShowItemFull(uil,c,pp,"_this_M_merge",0,"towards=LAST;text=Last",0,0);
- }
- int OPINV_NewRootObject(laOperator *a, laEvent *e){
- tnsCreateRootObject("Root"); laNotifyUsers("tns.world.root_objects"); laNotifyUsers("tns.world.active_root");
- return LA_FINISHED;
- }
- int OPCHK_RemoveRootObjects(laPropPack *This, laStringSplitor *ss){
- if(This && This->EndInstance){
- if(la_EnsureSubTarget(This->LastPs->p,0)!=TNS_PC_OBJECT_GENERIC) return 0;
- if(((tnsObject*)This->EndInstance)->Type!=TNS_OBJECT_ROOT) return 0;
- }else{ if(!T->World->ActiveRoot) return 0; }
- return 1;
- }
- int OPINV_RemoveRootObject(laOperator *a, laEvent *e){
- if(a->This && a->This->EndInstance){ tnsDestroyRootObject(a->This->EndInstance); }
- else{ tnsDestroyRootObject(T->World->ActiveRoot); }
- laNotifyUsers("tns.world.root_objects"); laNotifyUsers("tns.world.active_root");
- return LA_FINISHED;
- }
- void la_RegisterModellingOperators(){
- laPropContainer *pc; laProp *p;
- laOperatorType *at; laEnumProp *ep;
- laCreateOperatorType("M_new_root", "New Root", "Create a new root object", 0, 0, 0, OPINV_NewRootObject, 0, '+', 0);
- laCreateOperatorType("M_remove_root", "Remove Root", "Remove root object", OPCHK_RemoveRootObjects, 0, 0, OPINV_RemoveRootObject, 0 ,L'🗴', 0);
- laCreateOperatorType("M_set_cursor", "Set Cursor", "Set cursor in the viewport", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_SetCursor, 0, 0, LA_EXTRA_TO_PANEL);
- laCreateOperatorType("M_toggle_edit_mode", "Toggle Edit Mode", "Toggle edit mode of the active object", OPCHK_ThereIsActiveObject, 0, 0, OPINV_ToggleEdit, 0, 0, 0);
- laCreateOperatorType("M_select", "Select", "Select things in the viewport", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Select, OPMOD_Select, 0, LA_EXTRA_TO_PANEL);
- laCreateOperatorType("M_grab", "Grab", "Grab things and move around", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Grab, OPMOD_Transformation, 0, LA_EXTRA_TO_PANEL);
- laCreateOperatorType("M_scale", "Scale", "Scale selected things", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Scale, OPMOD_Transformation, 0, LA_EXTRA_TO_PANEL);
- laCreateOperatorType("M_rotate", "Rotate", "Rotation selected things", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Rotate, OPMOD_Transformation, 0, LA_EXTRA_TO_PANEL);
- at=laCreateOperatorType("M_clear_transformations", "Clear Transformations", "Clear object transformations", 0, 0, 0, OPINV_ClearTransformation, OPMOD_FinishOnData, 0, 0);
- at->UiDefine=laui_ClearTransformation;
- at=laCreateOperatorType("M_make_parent", "Make Parent", "Parent objects to active objects or unparent selected ones", 0, 0, 0, OPINV_MakeParent, OPMOD_FinishOnData, 0, 0);
- at->UiDefine = laui_MakeParent;
- at=laCreateOperatorType("M_unparent", "Unparent", "Unparent selected objects", 0, 0, 0, OPINV_MakeParent, OPMOD_FinishOnData, 0, 0);
- at->UiDefine = laui_Unparent;
- laCreateOperatorType("M_extrude", "Extrude", "Extrude parts of the mesh", 0, 0, 0, OPINV_Extrude, OPMOD_Transformation, 0, 0);
- at=laCreateOperatorType("M_delete", "Delete", "Delete parts of the mesh", 0, 0, 0, OPINV_Delete, OPMOD_FinishOnData, 0, 0);
- at->UiDefine=laui_Delete;
- laCreateOperatorType("M_make", "Make", "Make mesh primitive from selected ones", 0, 0, 0, OPINV_Make, 0, 0, 0);
- laCreateOperatorType("M_subdiv", "Subdiv", "Subdivide edges", 0, 0, 0, OPINV_Subdiv, 0, 0, 0);
- at=laCreateOperatorType("M_add", "Add", "Add mesh or primitives", 0, 0, 0, OPINV_Add, OPMOD_FinishOnData, 0, 0);
- at->UiDefine=laui_Add; pc = laDefineOperatorProps(at, 2);
- p=laAddEnumProperty(pc,"context","Context","Context of adding",0,0,0,0,0,offsetof(laObjectAddData,Context),0,0,0,0,0,0,0,0,0,0);
- laAddEnumItemAs(p,"OBJECT","Object","Object context",LA_ADD_CTX_OBJECT,0);
- laAddEnumItemAs(p,"MESH","Mesh","Mesh context",LA_ADD_CTX_MESH,0);
- laCreateOperatorType("M_separate", "Separate", "Separate mesh parts", 0, 0, 0, OPINV_Separate, 0, 0, 0);
- laCreateOperatorType("M_combine", "Combine", "Combine mesh objects", 0, 0, 0, OPINV_Combine, 0, 0, 0);
- laCreateOperatorType("M_duplicate", "Duplicate", "Duplicate objects", 0, 0, 0, OPINV_Duplicate, OPMOD_Transformation, 0, 0);
- laCreateOperatorType("M_recalculate_normals", "Recalculate Normals", "Recalculate normals", 0, 0, 0, OPINV_RecalculateNormals, 0, 0, 0);
- laCreateOperatorType("M_knife", "Knife", "Cut through edges", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Knife, OPMOD_Knife, 0, LA_EXTRA_TO_PANEL);
- at=laCreateOperatorType("M_merge", "Merge", "Merge vertices", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Merge, OPMOD_FinishOnData, 0, LA_EXTRA_TO_PANEL);
- at->UiDefine=laui_Merge;
- }
|