-
Notifications
You must be signed in to change notification settings - Fork 0
/
sculpt.js
3467 lines (2297 loc) · 99 KB
/
sculpt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var controlSystems;
var curControlSystem;
var dominantHand, otherHand;
var scene;
var selectedArtMesh;
var SCULPT_handChoiceFunc;
var SCULPT_editModeFunc;
var SCULPT_nextShapeFunc;
var SCULPT_selectionMethodChangeFunc;
var SCULPT_deleteArtOfUserId;
var SCULPT_permissionChange;
var SCULPT_selectionFloodAll;
var SCULPT_selectionFloodNone;
var SCULPT_saveSelection;
var SCULPT_isAnythingSelected;
var selectionModeIsClick;
var presentPalette, hidePalette;
var artCountList;
var archiveArt, placePrint, deleteArchive;
var ARTTYPES = makeEnum('stroke','prim','print','mannequin','costume');
var PEDESTALBUTTON = makeEnum('Single','Left','Right');
var DEBUG_COLORBUCKETS = false;
var vertexCutoff = 0xFFFF;
var faceCutoff = vertexCutoff/3;
// in theory I could rewrite this to use BufferGeometries, and then use literal vertex count instead of faces*3 (which is very wasteful in this case)
// buuuuuut let's just keep it simple for now; the multi-mesh case is so rare that it isn't worth worrying about too much
// and the last thing I need right now is debugging a new format like that
function SETUP_sculpt(){
var archiveFileFormat = [
{
name:"version",
type:DATANUMTYPES.integer,
count:DATACOUNT.single
},
{
name:"offY",
type:DATANUMTYPES.float,
count:DATACOUNT.single
},
{
name:"rad",
type:DATANUMTYPES.float,
count:DATACOUNT.single,
},
{
name:"strokes",
type:DATANUMTYPES.parent,
count:DATACOUNT.array,
child:[
{
name:"color",
type:DATANUMTYPES.integer,
count:DATACOUNT.single
},
{
name:"transform",
type:DATANUMTYPES.minimtx,
count:DATACOUNT.single
},
{
name:"vertices",
type:DATANUMTYPES.triple,
count:DATACOUNT.array
}
]
},
{
name:"prims",
type:DATANUMTYPES.parent,
count:DATACOUNT.array,
child:[
{
name:"color",
type:DATANUMTYPES.integer,
count:DATACOUNT.single
},
{
name:"transform",
type:DATANUMTYPES.minimtx,
count:DATACOUNT.single
},
{
name:"typeIndex",
type:DATANUMTYPES.integer,
count:DATACOUNT.single
}
]
},
{
name:"prints",
type:DATANUMTYPES.parent,
count:DATACOUNT.array,
child:[
{
name:"filename",
type:DATANUMTYPES.string,
count:DATACOUNT.single
},
{
name:"transform",
type:DATANUMTYPES.minimtx,
count:DATACOUNT.single
}
]
}
];
archiveArt = function(title,artSet,callback){
var strokesList = [];
var primsList = [];
var printsList = [];
artSet.forEach(function(curMesh){
switch(curMesh.artType){
case ARTTYPES.stroke:
strokesList.push(curMesh);
break;
case ARTTYPES.prim:
primsList.push(curMesh);
break;
case ARTTYPES.print:
printsList.push(curMesh);
break;
}
});
var saveData = {
version:1,
strokes:[],
prims:[],
prints:[]
};
function makeCenterFinder(){
var minVal;
var maxVal;
var firstPoint = true;
function addPoint(v){
if (firstPoint || (v < minVal)) minVal = v;
if (firstPoint || (v > maxVal)) maxVal = v;
firstPoint = false;
}
function getCenter(){
return (minVal+maxVal)/2;
}
function getEdge(){
var minEdge = minVal - getCenter();
var maxEdge = maxVal - getCenter();
return Math.max(Math.abs(minEdge),maxEdge);
}
return {
addPoint:addPoint,
getCenter:getCenter,
getEdge:getEdge
};
}
var midX = makeCenterFinder();
var midY = makeCenterFinder();
var midZ = makeCenterFinder();
for(var strokeIndex=0; strokeIndex<strokesList.length; strokeIndex++){
var curStrokeInfoSource = strokesList[strokeIndex];
midX.addPoint(curStrokeInfoSource.lastServerTransInfo.p[0]);
midY.addPoint(curStrokeInfoSource.lastServerTransInfo.p[1]);
midZ.addPoint(curStrokeInfoSource.lastServerTransInfo.p[2]);
// this isn't actually centered per se, but it's close enough to get a rough idea, which is all that's really needed tbh
}
for(var primIndex=0; primIndex<primsList.length; primIndex++){
var curPrimInfoSource = primsList[primIndex];
midX.addPoint(curPrimInfoSource.lastServerTransInfo.p[0]);
midY.addPoint(curPrimInfoSource.lastServerTransInfo.p[1]);
midZ.addPoint(curPrimInfoSource.lastServerTransInfo.p[2]);
}
for(var printIndex=0; printIndex<printsList.length; printIndex++){
var curPrintInfoSource = printsList[printIndex];
midX.addPoint(curPrintInfoSource.lastServerTransInfo.p[0]);
midY.addPoint(curPrintInfoSource.lastServerTransInfo.p[1]);
midZ.addPoint(curPrintInfoSource.lastServerTransInfo.p[2]);
}
var offX = midX.getCenter();
var offY = midY.getCenter();
var offZ = midZ.getCenter();
var saveRelativeToHeadY = headJoint.position.y;
saveData.offY = offY - saveRelativeToHeadY;
//worst-case scenario (though doesn't include dimensions of objects, only a rough cloud of their origins...)
saveData.rad = Math.max( midX.getEdge(), midY.getEdge(), midZ.getEdge() )/Math.cos(Math.PI/4);
function makeCenteredTransform(sourceTransform){
var offsettedTransform = {
p:[],
q:sourceTransform.q.slice(),
s:sourceTransform.s.slice()
};
offsettedTransform.p[0] = sourceTransform.p[0]-offX;
offsettedTransform.p[1] = sourceTransform.p[1]-offY;
offsettedTransform.p[2] = sourceTransform.p[2]-offZ;
return offsettedTransform;
}
for(var strokeIndex=0; strokeIndex<strokesList.length; strokeIndex++){
var curStrokeInfoSource = strokesList[strokeIndex];
var curStrokeInfoSave = {
color: curStrokeInfoSource.color,
transform: makeCenteredTransform(curStrokeInfoSource.lastServerTransInfo),
vertices:[]
};
var vertexList = curStrokeInfoSource.geometry.vertices;//should be safe to read from mesh rather than stored server info, right?
for(var vertexIndex=0; vertexIndex<vertexList.length; vertexIndex++){
curStrokeInfoSave.vertices.push({
x:vertexList[vertexIndex].x,
y:vertexList[vertexIndex].y,
z:vertexList[vertexIndex].z
});
}
saveData.strokes.push(curStrokeInfoSave);
}
for(var primIndex=0; primIndex<primsList.length; primIndex++){
var curPrimInfoSource = primsList[primIndex];
var curPrimInfoSave = {
color: curPrimInfoSource.color,
transform: makeCenteredTransform(curPrimInfoSource.lastServerTransInfo),
typeIndex: curPrimInfoSource.typeIndex
}
saveData.prims.push(curPrimInfoSave);
}
for(var printIndex=0; printIndex<printsList.length; printIndex++){
var curPrintInfoSource = printsList[printIndex];
var curPrintInfoSave = {
filename: curPrintInfoSource.filename,
transform: makeCenteredTransform(curPrintInfoSource.lastServerTransInfo)
}
saveData.prints.push(curPrintInfoSave);
}
var binaryArchive = packBinary(saveData,archiveFileFormat);
/*
console.log(saveData);
var DEBUGunpacked = unpackBinary(binaryArchive,archiveFileFormat);
console.log(DEBUGunpacked);
*/
var newFileInfoServer = myFilesServer.push();
var newFileName = newFileInfoServer.key;
var newFileRef = storageApp.child(newFileName);
var newFileTask = newFileRef.put(new Uint8Array(binaryArchive));
newFileTask.on('state_changed',function(snapshot){
console.log(snapshot.bytesTransferred,"/",snapshot.totalBytes);
},function(error){
console.log("UPLOAD ERROR:",error);
//callback();
},function(){
console.log("upload complete!!");
newFileInfoServer.set({
title:title,
timestamp:Date.now()
});
callback(
newFileInfoServer.key,
{
x:offX,
y:offY,
z:offZ
}
);
});
}
var archiveCaches = new Map();
var archiveCachesInProgress = new Map();
function loadArchive(id,callback){
if (archiveCaches.has(id)) {
setTimeout(function(){
callback(archiveCaches.get(id));
},0);
// logic is expecting callbacks, i.e. not returning immediately
} else if (archiveCachesInProgress.has(id)) {
archiveCachesInProgress.get(id).push(callback);
} else {
archiveCachesInProgress.set(id,[]);
//timeLog("requesting archive url...");
storageApp.child(id).getDownloadURL().then(function(url){
var artXhr = new XMLHttpRequest();
artXhr.responseType = "arraybuffer";
artXhr.onload = function(e){
//timeLog("binary transfer complete, beginning unpack...");
var loadedData = unpackBinary(artXhr.response,archiveFileFormat);
//timeLog("unpack complete, passing struct back to builder.");
archiveCaches.set(id,loadedData);
callback(loadedData);
var otherCallbacks = archiveCachesInProgress.get(id);
for(var i=0; i<otherCallbacks.length; i++) otherCallbacks[i](loadedData);
archiveCachesInProgress.delete(id);
}
artXhr.open('GET',url);
artXhr.send();
//timeLog("archive url get, requesting binary transfer...");
});
}
}
deleteArchive = function(id,callback){
// NOTE: the art data itself REMAINS ON THE SERVER, in case it's placed in the world anywhere.
// I could make it delete itself from all rooms too, but this doesn't seem worth the trouble.
// I've mainly added this feature so people's lists of art don't get cluttered, not for the server's sake.
myFilesServer.child(id).set(null);
if (callback) callback();//I'M NOT CURRENTLY ACTUALLY WAITING FOR THE SERVER TO NOTICE, because it doesn't really matter right now tbh
}
function iteratorToArray(iterator){
var theArray = [];
for(var entry of iterator){
theArray.push(entry);
}
return theArray;
}
placePrint = function(id){
//loading just to get at metadata, when we're about to load it again to display a moment later:
//sounds wasteful for network but in practice will be cached
loadArchive(id,function(loadedData){
var spawnPt = headJoint.position.clone();
var headVector = new THREE.Vector3(0,0,1);
headVector.applyQuaternion(headJoint.quaternion);
headVector.y = 0;
headVector.normalize();
headVector.multiplyScalar( 1.5+loadedData.rad );
spawnPt.add(headVector);
if (printLoadAsOptionInfo.getCurVal() == LOADAS.Art) {
spawnPt.y = headJoint.position.y + loadedData.offY;
placePrintOnServer(id,spawnPt);
} else {
myMannequinsServer.push({
printFilename:id,
bodypartIndex:costumeBodyPartOptionInfo.getCurVal().index,
mannequinTransform:{
p:[spawnPt.x,spawnPt.y,spawnPt.z],
q:[0,0,0,1],
s:[1,1,1]
},
costumeTransform:{
p:[0,0,0],
q:[0,0,0,1],
s:[1,1,1]
}
});
}
});
}
function placePrintOnServer(id,spawnPt){
myPrintsServer.push({
filename:id,
transform:{
p:[spawnPt.x,spawnPt.y,spawnPt.z],
q:[0,0,0,1],
s:[1,1,1]
},
movingFinished:true
});
}
function makeMtxFromMiniMtx(minimtx){
return new THREE.Matrix4().compose(
new THREE.Vector3(
minimtx.p[0],
minimtx.p[1],
minimtx.p[2]
),
new THREE.Quaternion(
minimtx.q[0],
minimtx.q[1],
minimtx.q[2],
minimtx.q[3]
),
new THREE.Vector3(
minimtx.s[0],
minimtx.s[1],
minimtx.s[2]
)
);
}
function makeServerTransformFromMtx(mtx){
var newPos = new THREE.Vector3();
var newRot = new THREE.Quaternion();
var newScl = new THREE.Vector3();
mtx.decompose(newPos,newRot,newScl);
return {
p:[newPos.x,newPos.y,newPos.z],
q:[newRot.x,newRot.y,newRot.z,newRot.w],
s:[newScl.x,newScl.y,newScl.z]
};
}
function makePrintFromArchive(filename,finishedCallback,parentMtx,passedAddArtToFunc){
loadArchive(filename,function(loadedData){
var holder;
var subMeshes;
var addArtToFunc;
if (!parentMtx) {//if 'root' call
holder = new THREE.Object3D();
subMeshes = [];
addArtToFunc = function(mesh,curParentMtx){
var newGeomFaces = mesh.geometry.faces.length;
var existingMeshChoice;
for(var subMeshIndex=0; subMeshIndex<subMeshes.length; subMeshIndex++){
if ( (subMeshes[subMeshIndex].geometry.faces.length + newGeomFaces) < faceCutoff/2 ) {//half to allow for double-sided clickability
existingMeshChoice = subMeshes[subMeshIndex];
break;
}
}
if (!existingMeshChoice) {
existingMeshChoice = new THREE.Mesh(
new THREE.Geometry(),
ribbonMat.clone()//altspace bug
);
if (DEBUG_COLORBUCKETS) existingMeshChoice.material.color = new THREE.Color(debugColorsList[subMeshes.length%debugColorsList.length]);
subMeshes.push(existingMeshChoice);
holder.add(existingMeshChoice);
}
if (curParentMtx) mesh.applyMatrix(curParentMtx);
existingMeshChoice.geometry.merge(mesh.geometry,mesh.matrix);
}
} else {
addArtToFunc = passedAddArtToFunc;
}
for(var strokeIndex=0; strokeIndex<loadedData.strokes.length; strokeIndex++){
var strokeInfo = loadedData.strokes[strokeIndex];
var vertices = [];
for(var vertIndex=0; vertIndex<strokeInfo.vertices.length; vertIndex+=2){
vertices.push([
strokeInfo.vertices[vertIndex],
strokeInfo.vertices[vertIndex+1],
]);
}
var strokeColor = new THREE.Color( DEBUG_COLORBUCKETS ? "#FFFFFF" : strokeInfo.color );
var strokeMesh = new THREE.Mesh( makeCompleteStrokeGeom(vertices,strokeColor) );
strokeMesh.applyMatrix(makeMtxFromMiniMtx(strokeInfo.transform));
addArtToFunc(strokeMesh,parentMtx);
}
for(var primIndex=0; primIndex<loadedData.prims.length; primIndex++){
var primInfo = loadedData.prims[primIndex];
var primColor = new THREE.Color( DEBUG_COLORBUCKETS ? "#FFFFFF" : primInfo.color );
var primMesh = new THREE.Mesh( makeCompletePrimGeom(primInfo.typeIndex, primColor) );
primMesh.applyMatrix(makeMtxFromMiniMtx(primInfo.transform));
addArtToFunc(primMesh,parentMtx);
}
var finishedPrints=0;
function onePrintFinished(){
finishedPrints++;
checkIfAllPrintsFinished();
}
function checkIfAllPrintsFinished(){
if (finishedPrints == loadedData.prints.length) {
if (parentMtx) {
finishedCallback();
} else {
for (var subMeshIndex=0; subMeshIndex<subMeshes.length; subMeshIndex++){
var curSubMesh = subMeshes[subMeshIndex];
curSubMesh.mergeGeom = curSubMesh.geometry.clone();
curSubMesh.geometry.copy( createDoubleSidedGeomClone(curSubMesh.mergeGeom) );//not sure if you can just assign to geometry; playing it safe
// note: I'm duplicating the primitives too even though they're already airtight, just because I can't be bothered doing that separately
// (in theory I could build both meshes in addArtToFunc but frankly I'm not going to bother;
// the real killer here is draw calls, not polycount)
}
//timeLog("print build finished!");
finishedCallback(holder);
}
}
}
for(var printIndex=0; printIndex<loadedData.prints.length; printIndex++){
var curPrintInfo = loadedData.prints[printIndex];
var curMtx = makeMtxFromMiniMtx(curPrintInfo.transform);
if (parentMtx) curMtx.multiply(parentMtx);
makePrintFromArchive(
curPrintInfo.filename,
onePrintFinished,
curMtx,
addArtToFunc
);
}
checkIfAllPrintsFinished();//do it once immediately, just in case there's zero prints
});
}
var renderer = altspace.getThreeJSRenderer({initialSerializationBufferSize: 8500000});
scene = new THREE.Scene();
var debugColorsList = [
0xFF0000,
0xFFFF00,
0x00FF00,
0x00FFFF,
0x0000FF,
0xFF00FF
];
var editModeVal;
function resizeDocumentToMetersWidth(w){
var docMeters = 128;
documentInfo.scale.set(w/docMeters,w/docMeters,w/docMeters);
}
function changeControlSystem(newControlSystem){
if (curControlSystem) {
console.log("] from "+curControlSystem.label+",");
curControlSystem.close();
}
console.log("] switching to "+newControlSystem.label);
curControlSystem = newControlSystem;
curControlSystem.open();
curControlSystem.modeSwitch(editModeVal);
curControlSystem.frameFunc();
stopAllInProgressDrawing();
if (palette_refreshControlSystem) palette_refreshControlSystem();
// the if statement is only for the initializing call, when the palette system hasn't initialized yet...
// it's okay to miss it there, since it'll auto-call itself when the pallete system sets up...
// this isn't a totally ideal way to do it, but it'll do?
}
var curPointsServer = null;
var cubeInProgress = null;
function endStrokeDrawing(deletedCurrentArt){
if (curPointsServer) {
var curDrawingFinishedServer = curPointsServer.parent.child('drawingFinished');
if (!deletedCurrentArt) curDrawingFinishedServer.set(true);
curDrawingFinishedServer.onDisconnect().cancel();
curPointsServer = null;
}
}
function endPrimDrawing(deletedCurrentArt){
if (cubeInProgress) {
var curCubeFinishedServer = cubeInProgress.child("movingFinished");
if (!deletedCurrentArt) curCubeFinishedServer.set(true);
curCubeFinishedServer.onDisconnect().cancel();
cubeInProgress = null;
}
}
function endSelection(deletedCurrentArt){
if (selectedArtMesh) {
markArtMovingFinished(selectedArtMesh,true,deletedCurrentArt);
selectedArtMesh = null;
}
curControlSystem.refreshArtSelected();
}
function stopAllInProgressDrawing(deletedCurrentArt){
console.log("resetting all drawing in progress...");
endStrokeDrawing(deletedCurrentArt);
endPrimDrawing(deletedCurrentArt);
endSelection(deletedCurrentArt);
if (SCULPT_selectionFloodNone) SCULPT_selectionFloodNone();//sigh
}
controlSystems = {
cursor: SETUP_cursor(),
tracked: SETUP_tracked()
};
var paletteIconOpenTex = THREE.ImageUtils.loadTexture("popup_icon.png");
var paletteIconCloseTex = THREE.ImageUtils.loadTexture("popup_icon_CLOSE.png");
var paletteIconMat = new THREE.MeshBasicMaterial({map:paletteIconOpenTex,transparent:true});
var paletteIconMesh = new THREE.Mesh(
new THREE.PlaneGeometry(0.1,0.1),
paletteIconMat
);
paletteIconMesh.position.set(
0.15,
0.6,
-1.2
);
paletteIconMesh.rotation.set(
-0.4,
0.6,
0,
'ZYX'
);
paletteIconMesh.position.applyEuler(paletteIconMesh.rotation);
new NativeComponent('n-cockpit-parent',null,paletteIconMesh).addTo(scene);
paletteIconMesh.userData.altspace.collider.enabled = true;
paletteIconMesh.addEventListener('cursordown',function(){
//console.log("PALETTE ICON CLICKED...");
if (paletteOpen) {
hidePalette();
} else {
presentPalette();
}
});
paletteIconMesh.name = "palette icon";
paletteIconMesh.UIBUTTON = true;
var removeAllCostumesButtonMesh = new THREE.Mesh(
new THREE.PlaneGeometry(0.1,0.1),
new THREE.MeshBasicMaterial({map:new THREE.ImageUtils.loadTexture("hangericon.png"),transparent:true})
);
removeAllCostumesButtonMesh.position.copy(paletteIconMesh.position);
removeAllCostumesButtonMesh.rotation.copy(paletteIconMesh.rotation);
var rightwards = new THREE.Vector3(0.15,0,0);
rightwards.applyEuler(removeAllCostumesButtonMesh.rotation);
removeAllCostumesButtonMesh.position.add(rightwards);
new NativeComponent('n-cockpit-parent',null,removeAllCostumesButtonMesh).addTo(scene);
removeAllCostumesButtonMesh.userData.altspace.collider.enabled = true;
removeAllCostumesButtonMesh.addEventListener('cursordown',function(){
personalWearingList.forEach(function(wearingInfo,wearingKey){ myWearingServer.child(wearingKey).remove(); });
refreshPedestalButtons();
});
removeAllCostumesButtonMesh.visible = false;
removeAllCostumesButtonMesh.UIBUTTON = true;
function refreshRemoveAllCostumesButtonVisible(){
removeAllCostumesButtonMesh.visible = !!personalWearingList.size;
}
var documentWorldSize = 2;
var documentDistance = 1.5;
var paletteHolder = new THREE.Object3D();
scene.add(paletteHolder);
paletteHolder.add(documentInfo);
documentInfo.position.set(0,0,documentDistance);
documentInfo.rotation.y = Math.PI;//for some reason!
resizeDocumentToMetersWidth(documentWorldSize);
/*
for(var i=-1; i<=1; i+=2){
var boxSize = 0.1;
var debugPlane = new THREE.Mesh(
new THREE.PlaneGeometry(boxSize,boxSize),
new THREE.MeshBasicMaterial({color:0xFF00FF})
);
paletteHolder.add(debugPlane);
debugPlane.position.set((documentWorldSize+boxSize)/2*i,(documentWorldSize+boxSize)/2*i*0.5825,documentDistance);
debugPlane.rotation.y = Math.PI;
}
*/
var bodyTag = document.getElementsByTagName("body")[0];
var paletteOpen = false;
presentPalette = function(){
paletteHolder.position.copy(headJoint.position);
paletteHolder.rotation.y = getHeadYaw();
paletteIconMat.map = paletteIconCloseTex;
paletteOpen = true;
bodyTag.style.display = "block";
}
hidePalette = function(){
paletteHolder.position.y = 1000000;
paletteIconMat.map = paletteIconOpenTex;
paletteOpen = false;
}
hidePalette();
SCULPT_permissionChange = function(){
paletteIconMesh.visible = permitted;
if (permitted) {
} else {
hidePalette();
stopAllInProgressDrawing();
}
}
var bowlOuterGeom = new THREE.SphereGeometry(0.5,16,8,0,Math.PI*2,0,Math.PI/2);
var bowlInnerGeom = new THREE.SphereGeometry(0.4,16,8,0,Math.PI*2,0,Math.PI/2);
var bowlTopGeom = new THREE.RingGeometry(0.4,0.5,16,1);
flipGeom(bowlInnerGeom);
var bowlOuterMesh = new THREE.Mesh( bowlOuterGeom );
var bowlInnerMesh = new THREE.Mesh( bowlInnerGeom );
var bowlTopMesh = new THREE.Mesh( bowlTopGeom );
bowlTopMesh.rotation.x = Math.PI/2;
var bowlHolder = new THREE.Object3D();
bowlHolder.add( bowlOuterMesh );
bowlHolder.add( bowlInnerMesh );
bowlHolder.add( bowlTopMesh );
var bowlGeom = mergeObjects([bowlOuterMesh,bowlInnerMesh,bowlTopMesh],bowlHolder);
var pyramidGeom = new THREE.CylinderGeometry(0,0.5,1,4,1,false,Math.PI/4);
pyramidGeom.computeFlatVertexNormals();
var donutThickness = 0.175;
var ringThickness = 0.04;
var pipeThickness = 0.1;
var pipeSides = 12;
var pipeBodyGeom = new THREE.TorusGeometry(0.5-pipeThickness,pipeThickness,pipeSides,pipeSides,Math.PI/2);
var pipeCapGeom = new THREE.CircleGeometry(pipeThickness,pipeSides);
var pipeBodyMesh = new THREE.Mesh( pipeBodyGeom );
var pipeStartMesh = new THREE.Mesh( pipeCapGeom );
var pipeEndMesh = new THREE.Mesh( pipeCapGeom );
var pipeHolder = new THREE.Object3D();
pipeHolder.add( pipeBodyMesh );
pipeHolder.add( pipeStartMesh );
pipeHolder.add( pipeEndMesh );
pipeBodyMesh.rotation.y = Math.PI/2;
pipeStartMesh.position.y = 0.5-pipeThickness;
pipeEndMesh.position.z = -(0.5-pipeThickness);
pipeEndMesh.rotation.x = Math.PI/2;
var pipeGeom = mergeObjects([pipeBodyMesh,pipeStartMesh,pipeEndMesh],pipeHolder);
var primGeoms = {};
primGeoms[SHAPEMODES.Cube.index] = new THREE.BoxGeometry(1,1,1);
primGeoms[SHAPEMODES.Ball.index] = new THREE.SphereGeometry(0.5,16,16);
primGeoms[SHAPEMODES.Bowl.index] = bowlGeom;
primGeoms[SHAPEMODES.Cylinder.index] = new THREE.CylinderGeometry(0.5,0.5,1,16,1);
primGeoms[SHAPEMODES.Cone.index] = new THREE.CylinderGeometry(0,0.5,1,16,1);
primGeoms[SHAPEMODES.Pyramid.index] = pyramidGeom;
primGeoms[SHAPEMODES.Donut.index] = new THREE.TorusGeometry(0.5-donutThickness,donutThickness,12,20).rotateY(Math.PI/2);
primGeoms[SHAPEMODES.Ring.index] = new THREE.TorusGeometry(0.5-ringThickness,ringThickness,6,24).rotateY(Math.PI/2);
primGeoms[SHAPEMODES.Pipe.index] = pipeGeom;