Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BlockGeometryGenerator.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
4 public class BlockGeometryGenerator {
5 public struct CornerLights {
6 public float L000;
7
8 public float L001;
9
10 public float L010;
11
12 public float L011;
13
14 public float L100;
15
16 public float L101;
17
18 public float L110;
19
20 public float L111;
21 }
22
23 public static Vector2[] m_textureCoordinates = [
24 new(0.001f, 0.999f),
25 new(0.999f, 0.999f),
26 new(0.999f, 0.001f),
27 new(0.001f, 0.001f),
28 new(0.001f, 0.999f),
29 new(0.999f, 0.999f),
30 new(0.999f, 0.001f),
31 new(0.001f, 0.001f)
32 ];
33
35
37
39
41
43
45
46 public DynamicArray<ElectricConnectionPath> m_tmpConnectionPaths = [];
47
49
51
52 public bool[] m_visibleSides = new bool[6];
53
55
57 SubsystemTerrain subsystemTerrain,
58 SubsystemElectricity subsystemElectricity,
59 SubsystemFurnitureBlockBehavior subsystemFurnitureBlockBehavior,
60 SubsystemMetersBlockBehavior subsystemMetersBlockBehavior,
61 SubsystemPalette subsystemPalette) {
62 Terrain = terrain;
63 SubsystemTerrain = subsystemTerrain;
64 SubsystemElectricity = subsystemElectricity;
65 SubsystemFurnitureBlockBehavior = subsystemFurnitureBlockBehavior;
66 SubsystemMetersBlockBehavior = subsystemMetersBlockBehavior;
67 SubsystemPalette = subsystemPalette;
68 ResetCache();
69 }
70
71 public void ResetCache() {
72 m_cornerLightsPosition = new Point3(2147483647);
73 }
74
75 public static void SetupCornerVertex(float x,
76 float y,
77 float z,
78 Color color,
79 int light,
80 int face,
81 int textureSlot,
82 int textureSlotCount,
83 int corner,
84 ref TerrainVertex vertex) {
85 float num = LightingManager.LightIntensityByLightValueAndFace[light + 16 * face];
86 Color color2 = new((byte)(color.R * num), (byte)(color.G * num), (byte)(color.B * num), color.A);
87 float tx = (m_textureCoordinates[corner].X + textureSlot % textureSlotCount) / textureSlotCount;
88 float ty = (m_textureCoordinates[corner].Y + textureSlot / textureSlotCount) / textureSlotCount;
90 x,
91 y,
92 z,
93 color2,
94 tx,
95 ty,
96 ref vertex
97 );
98 }
99
100 public static void SetupLitCornerVertex(float x,
101 float y,
102 float z,
103 Color color,
104 int textureSlot,
105 int corner,
106 ref TerrainVertex vertex) {
108 x,
109 y,
110 z,
111 color,
112 textureSlot,
113 16,
114 corner,
115 ref vertex
116 );
117 }
118
119 public static void SetupLitCornerVertex(float x,
120 float y,
121 float z,
122 Color color,
123 int textureSlot,
124 int textureSlotCount,
125 int corner,
126 ref TerrainVertex vertex) {
127 float tx = (m_textureCoordinates[corner].X + textureSlot % textureSlotCount) / textureSlotCount;
128 float ty = (m_textureCoordinates[corner].Y + textureSlot / textureSlotCount) / textureSlotCount;
130 x,
131 y,
132 z,
133 color,
134 tx,
135 ty,
136 ref vertex
137 );
138 }
139
140 public static void SetupVertex(float x,
141 float y,
142 float z,
143 Color color,
144 float tx,
145 float ty,
146 ref TerrainVertex vertex) {
147 vertex.X = x;
148 vertex.Y = y;
149 vertex.Z = z;
150 vertex.Tx = (short)(tx * 32767f);
151 vertex.Ty = (short)(ty * 32767f);
152 vertex.Color = color;
153 }
154
155 public virtual void GenerateCrossfaceVertices(Block block,
156 int value,
157 int x,
158 int y,
159 int z,
160 Color color,
161 int textureSlot,
162 TerrainGeometrySubset subset) {
163 DynamicArray<TerrainVertex> vertices = subset.Vertices;
164 TerrainGeometryDynamicArray<int> indices = subset.Indices;
165 int num = Terrain.ExtractLight(value);
167 Color color2 = new((byte)(color.R * num2), (byte)(color.G * num2), (byte)(color.B * num2), color.A);
168 int count = vertices.Count;
169 vertices.Count += 8;
170 int textureSlotCount = block.GetTextureSlotCount(value);
171 if ((x & 1) == 0) {
173 x,
174 y,
175 z,
176 color2,
177 textureSlot,
178 textureSlotCount,
179 0,
180 ref vertices.Array[count]
181 );
183 x + 1,
184 y,
185 z + 1,
186 color2,
187 textureSlot,
188 textureSlotCount,
189 1,
190 ref vertices.Array[count + 1]
191 );
193 x + 1,
194 y + 1,
195 z + 1,
196 color2,
197 textureSlot,
198 textureSlotCount,
199 2,
200 ref vertices.Array[count + 2]
201 );
203 x,
204 y + 1,
205 z,
206 color2,
207 textureSlot,
208 textureSlotCount,
209 3,
210 ref vertices.Array[count + 3]
211 );
212 }
213 else {
215 x,
216 y,
217 z,
218 color2,
219 textureSlot,
220 textureSlotCount,
221 1,
222 ref vertices.Array[count]
223 );
225 x + 1,
226 y,
227 z + 1,
228 color2,
229 textureSlot,
230 textureSlotCount,
231 0,
232 ref vertices.Array[count + 1]
233 );
235 x + 1,
236 y + 1,
237 z + 1,
238 color2,
239 textureSlot,
240 textureSlotCount,
241 3,
242 ref vertices.Array[count + 2]
243 );
245 x,
246 y + 1,
247 z,
248 color2,
249 textureSlot,
250 textureSlotCount,
251 2,
252 ref vertices.Array[count + 3]
253 );
254 }
255 if ((z & 1) == 0) {
257 x,
258 y,
259 z + 1,
260 color2,
261 textureSlot,
262 textureSlotCount,
263 0,
264 ref vertices.Array[count + 4]
265 );
267 x + 1,
268 y,
269 z,
270 color2,
271 textureSlot,
272 textureSlotCount,
273 1,
274 ref vertices.Array[count + 5]
275 );
277 x + 1,
278 y + 1,
279 z,
280 color2,
281 textureSlot,
282 textureSlotCount,
283 2,
284 ref vertices.Array[count + 6]
285 );
287 x,
288 y + 1,
289 z + 1,
290 color2,
291 textureSlot,
292 textureSlotCount,
293 3,
294 ref vertices.Array[count + 7]
295 );
296 }
297 else {
299 x,
300 y,
301 z + 1,
302 color2,
303 textureSlot,
304 textureSlotCount,
305 1,
306 ref vertices.Array[count + 4]
307 );
309 x + 1,
310 y,
311 z,
312 color2,
313 textureSlot,
314 textureSlotCount,
315 0,
316 ref vertices.Array[count + 5]
317 );
319 x + 1,
320 y + 1,
321 z,
322 color2,
323 textureSlot,
324 textureSlotCount,
325 3,
326 ref vertices.Array[count + 6]
327 );
329 x,
330 y + 1,
331 z + 1,
332 color2,
333 textureSlot,
334 textureSlotCount,
335 2,
336 ref vertices.Array[count + 7]
337 );
338 }
339 int count2 = indices.Count;
340 indices.Count += 24;
341 indices.Array[count2] = count;
342 indices.Array[count2 + 1] = count + 1;
343 indices.Array[count2 + 2] = count + 2;
344 indices.Array[count2 + 3] = count + 2;
345 indices.Array[count2 + 4] = count + 1;
346 indices.Array[count2 + 5] = count;
347 indices.Array[count2 + 6] = count + 2;
348 indices.Array[count2 + 7] = count + 3;
349 indices.Array[count2 + 8] = count;
350 indices.Array[count2 + 9] = count;
351 indices.Array[count2 + 10] = count + 3;
352 indices.Array[count2 + 11] = count + 2;
353 indices.Array[count2 + 12] = count + 4;
354 indices.Array[count2 + 13] = count + 5;
355 indices.Array[count2 + 14] = count + 6;
356 indices.Array[count2 + 15] = count + 6;
357 indices.Array[count2 + 16] = count + 5;
358 indices.Array[count2 + 17] = count + 4;
359 indices.Array[count2 + 18] = count + 6;
360 indices.Array[count2 + 19] = count + 7;
361 indices.Array[count2 + 20] = count + 4;
362 indices.Array[count2 + 21] = count + 4;
363 indices.Array[count2 + 22] = count + 7;
364 indices.Array[count2 + 23] = count + 6;
365 }
366
367 public virtual void GenerateCubeVertices(Block block,
368 int value,
369 int x,
370 int y,
371 int z,
372 Color color,
373 TerrainGeometrySubset[] subsetsByFace) {
374 int blockIndex = block.BlockIndex;
375 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z);
376 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x, z + 1);
377 TerrainChunk chunkAtCell3 = Terrain.GetChunkAtCell(x + 1, z);
378 TerrainChunk chunkAtCell4 = Terrain.GetChunkAtCell(x, z - 1);
379 TerrainChunk chunkAtCell5 = Terrain.GetChunkAtCell(x - 1, z);
380 int cellValueFast = chunkAtCell2.GetCellValueFast(x & 0xF, y, (z + 1) & 0xF);
381 int textureSlotCount = block.GetTextureSlotCount(value);
382 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
383 && block.ShouldGenerateFace(
385 0,
386 value,
387 cellValueFast,
388 x,
389 y,
390 z
391 )) {
392 DynamicArray<TerrainVertex> vertices = subsetsByFace[0].Vertices;
393 TerrainGeometryDynamicArray<int> indices = subsetsByFace[0].Indices;
394 int faceTextureSlot = block.GetFaceTextureSlot(0, value);
395 int count = vertices.Count;
396 vertices.Count += 4;
398 x,
399 y,
400 z + 1,
401 1f,
402 0,
403 faceTextureSlot,
404 textureSlotCount,
405 color,
406 ref vertices.Array[count]
407 ); //A
409 x + 1,
410 y,
411 z + 1,
412 1f,
413 1,
414 faceTextureSlot,
415 textureSlotCount,
416 color,
417 ref vertices.Array[count + 1]
418 ); //B
420 x + 1,
421 y + 1,
422 z + 1,
423 1f,
424 2,
425 faceTextureSlot,
426 textureSlotCount,
427 color,
428 ref vertices.Array[count + 2]
429 ); //C
431 x,
432 y + 1,
433 z + 1,
434 1f,
435 3,
436 faceTextureSlot,
437 textureSlotCount,
438 color,
439 ref vertices.Array[count + 3]
440 ); //D
441 int count2 = indices.Count;
442 indices.Count += 6;
443 indices.Array[count2] = count; //A
444 indices.Array[count2 + 1] = count + 2; //C
445 indices.Array[count2 + 2] = count + 1; //B
446 indices.Array[count2 + 3] = count + 2; //C
447 indices.Array[count2 + 4] = count; //A
448 indices.Array[count2 + 5] = count + 3; //D
449 }
450 cellValueFast = chunkAtCell3.GetCellValueFast((x + 1) & 0xF, y, z & 0xF);
451 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
452 && block.ShouldGenerateFace(
454 1,
455 value,
456 cellValueFast,
457 x,
458 y,
459 z
460 )) {
461 DynamicArray<TerrainVertex> vertices2 = subsetsByFace[1].Vertices;
462 TerrainGeometryDynamicArray<int> indices2 = subsetsByFace[1].Indices;
463 int faceTextureSlot2 = block.GetFaceTextureSlot(1, value);
464 int count3 = vertices2.Count;
465 vertices2.Count += 4;
467 x + 1,
468 y,
469 z,
470 1f,
471 1,
472 faceTextureSlot2,
473 textureSlotCount,
474 color,
475 ref vertices2.Array[count3]
476 );
478 x + 1,
479 y + 1,
480 z,
481 1f,
482 2,
483 faceTextureSlot2,
484 textureSlotCount,
485 color,
486 ref vertices2.Array[count3 + 1]
487 );
489 x + 1,
490 y + 1,
491 z + 1,
492 1f,
493 3,
494 faceTextureSlot2,
495 textureSlotCount,
496 color,
497 ref vertices2.Array[count3 + 2]
498 );
500 x + 1,
501 y,
502 z + 1,
503 1f,
504 0,
505 faceTextureSlot2,
506 textureSlotCount,
507 color,
508 ref vertices2.Array[count3 + 3]
509 );
510 int count4 = indices2.Count;
511 indices2.Count += 6;
512 indices2.Array[count4] = count3;
513 indices2.Array[count4 + 1] = count3 + 2;
514 indices2.Array[count4 + 2] = count3 + 1;
515 indices2.Array[count4 + 3] = count3 + 2;
516 indices2.Array[count4 + 4] = count3;
517 indices2.Array[count4 + 5] = count3 + 3;
518 }
519 cellValueFast = chunkAtCell4.GetCellValueFast(x & 0xF, y, (z - 1) & 0xF);
520 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
521 && block.ShouldGenerateFace(
523 2,
524 value,
525 cellValueFast,
526 x,
527 y,
528 z
529 )) {
530 DynamicArray<TerrainVertex> vertices3 = subsetsByFace[2].Vertices;
531 TerrainGeometryDynamicArray<int> indices3 = subsetsByFace[2].Indices;
532 int faceTextureSlot3 = block.GetFaceTextureSlot(2, value);
533 int count5 = vertices3.Count;
534 vertices3.Count += 4;
536 x,
537 y,
538 z,
539 1f,
540 1,
541 faceTextureSlot3,
542 textureSlotCount,
543 color,
544 ref vertices3.Array[count5]
545 );
547 x + 1,
548 y,
549 z,
550 1f,
551 0,
552 faceTextureSlot3,
553 textureSlotCount,
554 color,
555 ref vertices3.Array[count5 + 1]
556 );
558 x + 1,
559 y + 1,
560 z,
561 1f,
562 3,
563 faceTextureSlot3,
564 textureSlotCount,
565 color,
566 ref vertices3.Array[count5 + 2]
567 );
569 x,
570 y + 1,
571 z,
572 1f,
573 2,
574 faceTextureSlot3,
575 textureSlotCount,
576 color,
577 ref vertices3.Array[count5 + 3]
578 );
579 int count6 = indices3.Count;
580 indices3.Count += 6;
581 indices3.Array[count6] = count5;
582 indices3.Array[count6 + 1] = count5 + 1;
583 indices3.Array[count6 + 2] = count5 + 2;
584 indices3.Array[count6 + 3] = count5 + 2;
585 indices3.Array[count6 + 4] = count5 + 3;
586 indices3.Array[count6 + 5] = count5;
587 }
588 cellValueFast = chunkAtCell5.GetCellValueFast((x - 1) & 0xF, y, z & 0xF);
589 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
590 && block.ShouldGenerateFace(
592 3,
593 value,
594 cellValueFast,
595 x,
596 y,
597 z
598 )) {
599 DynamicArray<TerrainVertex> vertices4 = subsetsByFace[3].Vertices;
600 TerrainGeometryDynamicArray<int> indices4 = subsetsByFace[3].Indices;
601 int faceTextureSlot4 = block.GetFaceTextureSlot(3, value);
602 int count7 = vertices4.Count;
603 vertices4.Count += 4;
605 x,
606 y,
607 z,
608 1f,
609 0,
610 faceTextureSlot4,
611 textureSlotCount,
612 color,
613 ref vertices4.Array[count7]
614 );
616 x,
617 y + 1,
618 z,
619 1f,
620 3,
621 faceTextureSlot4,
622 textureSlotCount,
623 color,
624 ref vertices4.Array[count7 + 1]
625 );
627 x,
628 y + 1,
629 z + 1,
630 1f,
631 2,
632 faceTextureSlot4,
633 textureSlotCount,
634 color,
635 ref vertices4.Array[count7 + 2]
636 );
638 x,
639 y,
640 z + 1,
641 1f,
642 1,
643 faceTextureSlot4,
644 textureSlotCount,
645 color,
646 ref vertices4.Array[count7 + 3]
647 );
648 int count8 = indices4.Count;
649 indices4.Count += 6;
650 indices4.Array[count8] = count7;
651 indices4.Array[count8 + 1] = count7 + 1;
652 indices4.Array[count8 + 2] = count7 + 2;
653 indices4.Array[count8 + 3] = count7 + 2;
654 indices4.Array[count8 + 4] = count7 + 3;
655 indices4.Array[count8 + 5] = count7;
656 }
657 cellValueFast = chunkAtCell.GetCellValueFast(x & 0xF, y + 1, z & 0xF);
658 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
659 && block.ShouldGenerateFace(
661 4,
662 value,
663 cellValueFast,
664 x,
665 y,
666 z
667 )) {
668 DynamicArray<TerrainVertex> vertices5 = subsetsByFace[4].Vertices;
669 TerrainGeometryDynamicArray<int> indices5 = subsetsByFace[4].Indices;
670 int faceTextureSlot5 = block.GetFaceTextureSlot(4, value);
671 int count9 = vertices5.Count;
672 vertices5.Count += 4;
674 x,
675 y + 1,
676 z,
677 1f,
678 3,
679 faceTextureSlot5,
680 textureSlotCount,
681 color,
682 ref vertices5.Array[count9]
683 );
685 x + 1,
686 y + 1,
687 z,
688 1f,
689 2,
690 faceTextureSlot5,
691 textureSlotCount,
692 color,
693 ref vertices5.Array[count9 + 1]
694 );
696 x + 1,
697 y + 1,
698 z + 1,
699 1f,
700 1,
701 faceTextureSlot5,
702 textureSlotCount,
703 color,
704 ref vertices5.Array[count9 + 2]
705 );
707 x,
708 y + 1,
709 z + 1,
710 1f,
711 0,
712 faceTextureSlot5,
713 textureSlotCount,
714 color,
715 ref vertices5.Array[count9 + 3]
716 );
717 int count10 = indices5.Count;
718 indices5.Count += 6;
719 indices5.Array[count10] = count9;
720 indices5.Array[count10 + 1] = count9 + 1;
721 indices5.Array[count10 + 2] = count9 + 2;
722 indices5.Array[count10 + 3] = count9 + 2;
723 indices5.Array[count10 + 4] = count9 + 3;
724 indices5.Array[count10 + 5] = count9;
725 }
726 cellValueFast = chunkAtCell.GetCellValueFast(x & 0xF, y - 1, z & 0xF);
727 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
728 && block.ShouldGenerateFace(
730 5,
731 value,
732 cellValueFast,
733 x,
734 y,
735 z
736 )) {
737 DynamicArray<TerrainVertex> vertices6 = subsetsByFace[5].Vertices;
738 TerrainGeometryDynamicArray<int> indices6 = subsetsByFace[5].Indices;
739 int faceTextureSlot6 = block.GetFaceTextureSlot(5, value);
740 int count11 = vertices6.Count;
741 vertices6.Count += 4;
743 x,
744 y,
745 z,
746 1f,
747 0,
748 faceTextureSlot6,
749 textureSlotCount,
750 color,
751 ref vertices6.Array[count11]
752 );
754 x + 1,
755 y,
756 z,
757 1f,
758 1,
759 faceTextureSlot6,
760 textureSlotCount,
761 color,
762 ref vertices6.Array[count11 + 1]
763 );
765 x + 1,
766 y,
767 z + 1,
768 1f,
769 2,
770 faceTextureSlot6,
771 textureSlotCount,
772 color,
773 ref vertices6.Array[count11 + 2]
774 );
776 x,
777 y,
778 z + 1,
779 1f,
780 3,
781 faceTextureSlot6,
782 textureSlotCount,
783 color,
784 ref vertices6.Array[count11 + 3]
785 );
786 int count12 = indices6.Count;
787 indices6.Count += 6;
788 indices6.Array[count12] = count11;
789 indices6.Array[count12 + 1] = count11 + 2;
790 indices6.Array[count12 + 2] = count11 + 1;
791 indices6.Array[count12 + 3] = count11 + 2;
792 indices6.Array[count12 + 4] = count11;
793 indices6.Array[count12 + 5] = count11 + 3;
794 }
795 }
796
797 public virtual void GenerateCubeVertices(Block block,
798 int value,
799 int x,
800 int y,
801 int z,
802 float height11,
803 float height21,
804 float height22,
805 float height12,
806 Color sideColor,
807 Color topColor11,
808 Color topColor21,
809 Color topColor22,
810 Color topColor12,
811 int overrideTopTextureSlot,
812 TerrainGeometrySubset[] subsetsByFace) {
813 int blockIndex = block.BlockIndex;
814 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z);
815 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x, z + 1);
816 TerrainChunk chunkAtCell3 = Terrain.GetChunkAtCell(x + 1, z);
817 TerrainChunk chunkAtCell4 = Terrain.GetChunkAtCell(x, z - 1);
818 TerrainChunk chunkAtCell5 = Terrain.GetChunkAtCell(x - 1, z);
819 int cellValueFast = chunkAtCell2.GetCellValueFast(x & 0xF, y, (z + 1) & 0xF);
820 int textureSlotCount = block.GetTextureSlotCount(value);
821 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
822 && block.ShouldGenerateFace(
824 0,
825 value,
826 cellValueFast,
827 x,
828 y,
829 z
830 )) {
831 DynamicArray<TerrainVertex> vertices = subsetsByFace[0].Vertices;
832 TerrainGeometryDynamicArray<int> indices = subsetsByFace[0].Indices;
833 int faceTextureSlot = block.GetFaceTextureSlot(0, value);
834 int count = vertices.Count;
835 vertices.Count += 4;
837 x,
838 y,
839 z + 1,
840 1f,
841 0,
842 faceTextureSlot,
843 textureSlotCount,
844 sideColor,
845 ref vertices.Array[count]
846 );
848 x + 1,
849 y,
850 z + 1,
851 1f,
852 1,
853 faceTextureSlot,
854 textureSlotCount,
855 sideColor,
856 ref vertices.Array[count + 1]
857 );
859 x + 1,
860 y + 1,
861 z + 1,
862 height22,
863 2,
864 faceTextureSlot,
865 textureSlotCount,
866 sideColor,
867 ref vertices.Array[count + 2]
868 );
870 x,
871 y + 1,
872 z + 1,
873 height12,
874 3,
875 faceTextureSlot,
876 textureSlotCount,
877 sideColor,
878 ref vertices.Array[count + 3]
879 );
880 int count2 = indices.Count;
881 indices.Count += 6;
882 indices.Array[count2] = count;
883 indices.Array[count2 + 1] = count + 2;
884 indices.Array[count2 + 2] = count + 1;
885 indices.Array[count2 + 3] = count + 2;
886 indices.Array[count2 + 4] = count;
887 indices.Array[count2 + 5] = count + 3;
888 }
889 cellValueFast = chunkAtCell3.GetCellValueFast((x + 1) & 0xF, y, z & 0xF);
890 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
891 && block.ShouldGenerateFace(
893 1,
894 value,
895 cellValueFast,
896 x,
897 y,
898 z
899 )) {
900 DynamicArray<TerrainVertex> vertices2 = subsetsByFace[1].Vertices;
901 TerrainGeometryDynamicArray<int> indices2 = subsetsByFace[1].Indices;
902 int faceTextureSlot2 = block.GetFaceTextureSlot(1, value);
903 int count3 = vertices2.Count;
904 vertices2.Count += 4;
906 x + 1,
907 y,
908 z,
909 1f,
910 1,
911 faceTextureSlot2,
912 textureSlotCount,
913 sideColor,
914 ref vertices2.Array[count3]
915 );
917 x + 1,
918 y + 1,
919 z,
920 height21,
921 2,
922 faceTextureSlot2,
923 textureSlotCount,
924 sideColor,
925 ref vertices2.Array[count3 + 1]
926 );
928 x + 1,
929 y + 1,
930 z + 1,
931 height22,
932 3,
933 faceTextureSlot2,
934 textureSlotCount,
935 sideColor,
936 ref vertices2.Array[count3 + 2]
937 );
939 x + 1,
940 y,
941 z + 1,
942 1f,
943 0,
944 faceTextureSlot2,
945 textureSlotCount,
946 sideColor,
947 ref vertices2.Array[count3 + 3]
948 );
949 int count4 = indices2.Count;
950 indices2.Count += 6;
951 indices2.Array[count4] = count3;
952 indices2.Array[count4 + 1] = count3 + 2;
953 indices2.Array[count4 + 2] = count3 + 1;
954 indices2.Array[count4 + 3] = count3 + 2;
955 indices2.Array[count4 + 4] = count3;
956 indices2.Array[count4 + 5] = count3 + 3;
957 }
958 cellValueFast = chunkAtCell4.GetCellValueFast(x & 0xF, y, (z - 1) & 0xF);
959 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
960 && block.ShouldGenerateFace(
962 2,
963 value,
964 cellValueFast,
965 x,
966 y,
967 z
968 )) {
969 DynamicArray<TerrainVertex> vertices3 = subsetsByFace[2].Vertices;
970 TerrainGeometryDynamicArray<int> indices3 = subsetsByFace[2].Indices;
971 int faceTextureSlot3 = block.GetFaceTextureSlot(2, value);
972 int count5 = vertices3.Count;
973 vertices3.Count += 4;
975 x,
976 y,
977 z,
978 1f,
979 1,
980 faceTextureSlot3,
981 textureSlotCount,
982 sideColor,
983 ref vertices3.Array[count5]
984 );
986 x + 1,
987 y,
988 z,
989 1f,
990 0,
991 faceTextureSlot3,
992 textureSlotCount,
993 sideColor,
994 ref vertices3.Array[count5 + 1]
995 );
997 x + 1,
998 y + 1,
999 z,
1000 height21,
1001 3,
1002 faceTextureSlot3,
1003 textureSlotCount,
1004 sideColor,
1005 ref vertices3.Array[count5 + 2]
1006 );
1008 x,
1009 y + 1,
1010 z,
1011 height11,
1012 2,
1013 faceTextureSlot3,
1014 textureSlotCount,
1015 sideColor,
1016 ref vertices3.Array[count5 + 3]
1017 );
1018 int count6 = indices3.Count;
1019 indices3.Count += 6;
1020 indices3.Array[count6] = count5;
1021 indices3.Array[count6 + 1] = count5 + 1;
1022 indices3.Array[count6 + 2] = count5 + 2;
1023 indices3.Array[count6 + 3] = count5 + 2;
1024 indices3.Array[count6 + 4] = count5 + 3;
1025 indices3.Array[count6 + 5] = count5;
1026 }
1027 cellValueFast = chunkAtCell5.GetCellValueFast((x - 1) & 0xF, y, z & 0xF);
1028 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1029 && block.ShouldGenerateFace(
1031 3,
1032 value,
1033 cellValueFast,
1034 x,
1035 y,
1036 z
1037 )) {
1038 DynamicArray<TerrainVertex> vertices4 = subsetsByFace[3].Vertices;
1039 TerrainGeometryDynamicArray<int> indices4 = subsetsByFace[3].Indices;
1040 int faceTextureSlot4 = block.GetFaceTextureSlot(3, value);
1041 int count7 = vertices4.Count;
1042 vertices4.Count += 4;
1044 x,
1045 y,
1046 z,
1047 1f,
1048 0,
1049 faceTextureSlot4,
1050 textureSlotCount,
1051 sideColor,
1052 ref vertices4.Array[count7]
1053 );
1055 x,
1056 y + 1,
1057 z,
1058 height11,
1059 3,
1060 faceTextureSlot4,
1061 textureSlotCount,
1062 sideColor,
1063 ref vertices4.Array[count7 + 1]
1064 );
1066 x,
1067 y + 1,
1068 z + 1,
1069 height12,
1070 2,
1071 faceTextureSlot4,
1072 textureSlotCount,
1073 sideColor,
1074 ref vertices4.Array[count7 + 2]
1075 );
1077 x,
1078 y,
1079 z + 1,
1080 1f,
1081 1,
1082 faceTextureSlot4,
1083 textureSlotCount,
1084 sideColor,
1085 ref vertices4.Array[count7 + 3]
1086 );
1087 int count8 = indices4.Count;
1088 indices4.Count += 6;
1089 indices4.Array[count8] = count7;
1090 indices4.Array[count8 + 1] = count7 + 1;
1091 indices4.Array[count8 + 2] = count7 + 2;
1092 indices4.Array[count8 + 3] = count7 + 2;
1093 indices4.Array[count8 + 4] = count7 + 3;
1094 indices4.Array[count8 + 5] = count7;
1095 }
1096 cellValueFast = chunkAtCell.GetCellValueFast(x & 0xF, y + 1, z & 0xF);
1097 if (((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1098 && block.ShouldGenerateFace(
1100 4,
1101 value,
1102 cellValueFast,
1103 x,
1104 y,
1105 z
1106 ))
1107 || height11 < 1f
1108 || height12 < 1f
1109 || height21 < 1f
1110 || height22 < 1f) {
1111 DynamicArray<TerrainVertex> vertices5 = subsetsByFace[4].Vertices;
1112 TerrainGeometryDynamicArray<int> indices5 = subsetsByFace[4].Indices;
1113 int textureSlot = overrideTopTextureSlot >= 0 ? overrideTopTextureSlot : block.GetFaceTextureSlot(4, value);
1114 int count9 = vertices5.Count;
1115 vertices5.Count += 4;
1117 x,
1118 y + 1,
1119 z,
1120 height11,
1121 3,
1122 textureSlot,
1123 textureSlotCount,
1124 topColor11,
1125 ref vertices5.Array[count9]
1126 );
1128 x + 1,
1129 y + 1,
1130 z,
1131 height21,
1132 2,
1133 textureSlot,
1134 textureSlotCount,
1135 topColor21,
1136 ref vertices5.Array[count9 + 1]
1137 );
1139 x + 1,
1140 y + 1,
1141 z + 1,
1142 height22,
1143 1,
1144 textureSlot,
1145 textureSlotCount,
1146 topColor22,
1147 ref vertices5.Array[count9 + 2]
1148 );
1150 x,
1151 y + 1,
1152 z + 1,
1153 height12,
1154 0,
1155 textureSlot,
1156 textureSlotCount,
1157 topColor12,
1158 ref vertices5.Array[count9 + 3]
1159 );
1160 int count10 = indices5.Count;
1161 indices5.Count += 6;
1162 indices5.Array[count10] = count9;
1163 indices5.Array[count10 + 1] = count9 + 1;
1164 indices5.Array[count10 + 2] = count9 + 2;
1165 indices5.Array[count10 + 3] = count9 + 2;
1166 indices5.Array[count10 + 4] = count9 + 3;
1167 indices5.Array[count10 + 5] = count9;
1168 }
1169 cellValueFast = chunkAtCell.GetCellValueFast(x & 0xF, y - 1, z & 0xF);
1170 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1171 && block.ShouldGenerateFace(
1173 5,
1174 value,
1175 cellValueFast,
1176 x,
1177 y,
1178 z
1179 )) {
1180 DynamicArray<TerrainVertex> vertices6 = subsetsByFace[5].Vertices;
1181 TerrainGeometryDynamicArray<int> indices6 = subsetsByFace[5].Indices;
1182 int faceTextureSlot5 = block.GetFaceTextureSlot(5, value);
1183 int count11 = vertices6.Count;
1184 vertices6.Count += 4;
1186 x,
1187 y,
1188 z,
1189 1f,
1190 0,
1191 faceTextureSlot5,
1192 textureSlotCount,
1193 sideColor,
1194 ref vertices6.Array[count11]
1195 );
1197 x + 1,
1198 y,
1199 z,
1200 1f,
1201 1,
1202 faceTextureSlot5,
1203 textureSlotCount,
1204 sideColor,
1205 ref vertices6.Array[count11 + 1]
1206 );
1208 x + 1,
1209 y,
1210 z + 1,
1211 1f,
1212 2,
1213 faceTextureSlot5,
1214 textureSlotCount,
1215 sideColor,
1216 ref vertices6.Array[count11 + 2]
1217 );
1219 x,
1220 y,
1221 z + 1,
1222 1f,
1223 3,
1224 faceTextureSlot5,
1225 textureSlotCount,
1226 sideColor,
1227 ref vertices6.Array[count11 + 3]
1228 );
1229 int count12 = indices6.Count;
1230 indices6.Count += 6;
1231 indices6.Array[count12] = count11;
1232 indices6.Array[count12 + 1] = count11 + 2;
1233 indices6.Array[count12 + 2] = count11 + 1;
1234 indices6.Array[count12 + 3] = count11 + 2;
1235 indices6.Array[count12 + 4] = count11;
1236 indices6.Array[count12 + 5] = count11 + 3;
1237 }
1238 }
1239
1240 public virtual void GenerateCubeVertices(Block block,
1241 int value,
1242 int x,
1243 int y,
1244 int z,
1245 int rotationX,
1246 int rotationY,
1247 int rotationZ,
1248 Color color,
1249 TerrainGeometrySubset[] subsetsByFace) {
1250 int blockIndex = block.BlockIndex;
1251 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z);
1252 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x, z + 1);
1253 TerrainChunk chunkAtCell3 = Terrain.GetChunkAtCell(x + 1, z);
1254 TerrainChunk chunkAtCell4 = Terrain.GetChunkAtCell(x, z - 1);
1255 TerrainChunk chunkAtCell5 = Terrain.GetChunkAtCell(x - 1, z);
1256 int cellValueFast = chunkAtCell2.GetCellValueFast(x & 0xF, y, (z + 1) & 0xF);
1257 int textureSlotCount = block.GetTextureSlotCount(value);
1258 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1259 && block.ShouldGenerateFace(
1261 0,
1262 value,
1263 cellValueFast,
1264 x,
1265 y,
1266 z
1267 )) {
1268 DynamicArray<TerrainVertex> vertices = subsetsByFace[0].Vertices;
1269 TerrainGeometryDynamicArray<int> indices = subsetsByFace[0].Indices;
1270 int faceTextureSlot = block.GetFaceTextureSlot(0, value);
1271 int count = vertices.Count;
1272 vertices.Count += 4;
1274 x,
1275 y,
1276 z + 1,
1277 1f,
1278 rotationZ,
1279 faceTextureSlot,
1280 textureSlotCount,
1281 color,
1282 ref vertices.Array[count]
1283 );
1285 x + 1,
1286 y,
1287 z + 1,
1288 1f,
1289 1 + rotationZ,
1290 faceTextureSlot,
1291 textureSlotCount,
1292 color,
1293 ref vertices.Array[count + 1]
1294 );
1296 x + 1,
1297 y + 1,
1298 z + 1,
1299 1f,
1300 2 + rotationZ,
1301 faceTextureSlot,
1302 textureSlotCount,
1303 color,
1304 ref vertices.Array[count + 2]
1305 );
1307 x,
1308 y + 1,
1309 z + 1,
1310 1f,
1311 3 + rotationZ,
1312 faceTextureSlot,
1313 textureSlotCount,
1314 color,
1315 ref vertices.Array[count + 3]
1316 );
1317 int count2 = indices.Count;
1318 indices.Count += 6;
1319 indices.Array[count2] = count;
1320 indices.Array[count2 + 1] = count + 2;
1321 indices.Array[count2 + 2] = count + 1;
1322 indices.Array[count2 + 3] = count + 2;
1323 indices.Array[count2 + 4] = count;
1324 indices.Array[count2 + 5] = count + 3;
1325 }
1326 cellValueFast = chunkAtCell3.GetCellValueFast((x + 1) & 0xF, y, z & 0xF);
1327 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1328 && block.ShouldGenerateFace(
1330 1,
1331 value,
1332 cellValueFast,
1333 x,
1334 y,
1335 z
1336 )) {
1337 DynamicArray<TerrainVertex> vertices2 = subsetsByFace[1].Vertices;
1338 TerrainGeometryDynamicArray<int> indices2 = subsetsByFace[1].Indices;
1339 int faceTextureSlot2 = block.GetFaceTextureSlot(1, value);
1340 int count3 = vertices2.Count;
1341 vertices2.Count += 4;
1343 x + 1,
1344 y,
1345 z,
1346 1f,
1347 1 + rotationX,
1348 faceTextureSlot2,
1349 textureSlotCount,
1350 color,
1351 ref vertices2.Array[count3]
1352 );
1354 x + 1,
1355 y + 1,
1356 z,
1357 1f,
1358 2 + rotationX,
1359 faceTextureSlot2,
1360 textureSlotCount,
1361 color,
1362 ref vertices2.Array[count3 + 1]
1363 );
1365 x + 1,
1366 y + 1,
1367 z + 1,
1368 1f,
1369 3 + rotationX,
1370 faceTextureSlot2,
1371 textureSlotCount,
1372 color,
1373 ref vertices2.Array[count3 + 2]
1374 );
1376 x + 1,
1377 y,
1378 z + 1,
1379 1f,
1380 rotationX,
1381 faceTextureSlot2,
1382 textureSlotCount,
1383 color,
1384 ref vertices2.Array[count3 + 3]
1385 );
1386 int count4 = indices2.Count;
1387 indices2.Count += 6;
1388 indices2.Array[count4] = count3;
1389 indices2.Array[count4 + 1] = count3 + 2;
1390 indices2.Array[count4 + 2] = count3 + 1;
1391 indices2.Array[count4 + 3] = count3 + 2;
1392 indices2.Array[count4 + 4] = count3;
1393 indices2.Array[count4 + 5] = count3 + 3;
1394 }
1395 cellValueFast = chunkAtCell4.GetCellValueFast(x & 0xF, y, (z - 1) & 0xF);
1396 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1397 && block.ShouldGenerateFace(
1399 2,
1400 value,
1401 cellValueFast,
1402 x,
1403 y,
1404 z
1405 )) {
1406 DynamicArray<TerrainVertex> vertices3 = subsetsByFace[2].Vertices;
1407 TerrainGeometryDynamicArray<int> indices3 = subsetsByFace[2].Indices;
1408 int faceTextureSlot3 = block.GetFaceTextureSlot(2, value);
1409 int count5 = vertices3.Count;
1410 vertices3.Count += 4;
1412 x,
1413 y,
1414 z,
1415 1f,
1416 1 + rotationZ,
1417 faceTextureSlot3,
1418 textureSlotCount,
1419 color,
1420 ref vertices3.Array[count5]
1421 );
1423 x + 1,
1424 y,
1425 z,
1426 1f,
1427 rotationZ,
1428 faceTextureSlot3,
1429 textureSlotCount,
1430 color,
1431 ref vertices3.Array[count5 + 1]
1432 );
1434 x + 1,
1435 y + 1,
1436 z,
1437 1f,
1438 3 + rotationZ,
1439 faceTextureSlot3,
1440 textureSlotCount,
1441 color,
1442 ref vertices3.Array[count5 + 2]
1443 );
1445 x,
1446 y + 1,
1447 z,
1448 1f,
1449 2 + rotationZ,
1450 faceTextureSlot3,
1451 textureSlotCount,
1452 color,
1453 ref vertices3.Array[count5 + 3]
1454 );
1455 int count6 = indices3.Count;
1456 indices3.Count += 6;
1457 indices3.Array[count6] = count5;
1458 indices3.Array[count6 + 1] = count5 + 1;
1459 indices3.Array[count6 + 2] = count5 + 2;
1460 indices3.Array[count6 + 3] = count5 + 2;
1461 indices3.Array[count6 + 4] = count5 + 3;
1462 indices3.Array[count6 + 5] = count5;
1463 }
1464 cellValueFast = chunkAtCell5.GetCellValueFast((x - 1) & 0xF, y, z & 0xF);
1465 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1466 && block.ShouldGenerateFace(
1468 3,
1469 value,
1470 cellValueFast,
1471 x,
1472 y,
1473 z
1474 )) {
1475 DynamicArray<TerrainVertex> vertices4 = subsetsByFace[3].Vertices;
1476 TerrainGeometryDynamicArray<int> indices4 = subsetsByFace[3].Indices;
1477 int faceTextureSlot4 = block.GetFaceTextureSlot(3, value);
1478 int count7 = vertices4.Count;
1479 vertices4.Count += 4;
1481 x,
1482 y,
1483 z,
1484 1f,
1485 rotationX,
1486 faceTextureSlot4,
1487 textureSlotCount,
1488 color,
1489 ref vertices4.Array[count7]
1490 );
1492 x,
1493 y + 1,
1494 z,
1495 1f,
1496 3 + rotationX,
1497 faceTextureSlot4,
1498 textureSlotCount,
1499 color,
1500 ref vertices4.Array[count7 + 1]
1501 );
1503 x,
1504 y + 1,
1505 z + 1,
1506 1f,
1507 2 + rotationX,
1508 faceTextureSlot4,
1509 textureSlotCount,
1510 color,
1511 ref vertices4.Array[count7 + 2]
1512 );
1514 x,
1515 y,
1516 z + 1,
1517 1f,
1518 1 + rotationX,
1519 faceTextureSlot4,
1520 textureSlotCount,
1521 color,
1522 ref vertices4.Array[count7 + 3]
1523 );
1524 int count8 = indices4.Count;
1525 indices4.Count += 6;
1526 indices4.Array[count8] = count7;
1527 indices4.Array[count8 + 1] = count7 + 1;
1528 indices4.Array[count8 + 2] = count7 + 2;
1529 indices4.Array[count8 + 3] = count7 + 2;
1530 indices4.Array[count8 + 4] = count7 + 3;
1531 indices4.Array[count8 + 5] = count7;
1532 }
1533 cellValueFast = chunkAtCell.GetCellValueFast(x & 0xF, y + 1, z & 0xF);
1534 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1535 && block.ShouldGenerateFace(
1537 4,
1538 value,
1539 cellValueFast,
1540 x,
1541 y,
1542 z
1543 )) {
1544 DynamicArray<TerrainVertex> vertices5 = subsetsByFace[4].Vertices;
1545 TerrainGeometryDynamicArray<int> indices5 = subsetsByFace[4].Indices;
1546 int faceTextureSlot5 = block.GetFaceTextureSlot(4, value);
1547 int count9 = vertices5.Count;
1548 vertices5.Count += 4;
1550 x,
1551 y + 1,
1552 z,
1553 1f,
1554 3 + rotationY,
1555 faceTextureSlot5,
1556 textureSlotCount,
1557 color,
1558 ref vertices5.Array[count9]
1559 );
1561 x + 1,
1562 y + 1,
1563 z,
1564 1f,
1565 2 + rotationY,
1566 faceTextureSlot5,
1567 textureSlotCount,
1568 color,
1569 ref vertices5.Array[count9 + 1]
1570 );
1572 x + 1,
1573 y + 1,
1574 z + 1,
1575 1f,
1576 1 + rotationY,
1577 faceTextureSlot5,
1578 textureSlotCount,
1579 color,
1580 ref vertices5.Array[count9 + 2]
1581 );
1583 x,
1584 y + 1,
1585 z + 1,
1586 1f,
1587 rotationY,
1588 faceTextureSlot5,
1589 textureSlotCount,
1590 color,
1591 ref vertices5.Array[count9 + 3]
1592 );
1593 int count10 = indices5.Count;
1594 indices5.Count += 6;
1595 indices5.Array[count10] = count9;
1596 indices5.Array[count10 + 1] = count9 + 1;
1597 indices5.Array[count10 + 2] = count9 + 2;
1598 indices5.Array[count10 + 3] = count9 + 2;
1599 indices5.Array[count10 + 4] = count9 + 3;
1600 indices5.Array[count10 + 5] = count9;
1601 }
1602 cellValueFast = chunkAtCell.GetCellValueFast(x & 0xF, y - 1, z & 0xF);
1603 if ((block.GenerateFacesForSameNeighbors || Terrain.ExtractContents(cellValueFast) != blockIndex)
1604 && block.ShouldGenerateFace(
1606 5,
1607 value,
1608 cellValueFast,
1609 x,
1610 y,
1611 z
1612 )) {
1613 DynamicArray<TerrainVertex> vertices6 = subsetsByFace[5].Vertices;
1614 TerrainGeometryDynamicArray<int> indices6 = subsetsByFace[5].Indices;
1615 int faceTextureSlot6 = block.GetFaceTextureSlot(5, value);
1616 int count11 = vertices6.Count;
1617 vertices6.Count += 4;
1619 x,
1620 y,
1621 z,
1622 1f,
1623 rotationY,
1624 faceTextureSlot6,
1625 textureSlotCount,
1626 color,
1627 ref vertices6.Array[count11]
1628 );
1630 x + 1,
1631 y,
1632 z,
1633 1f,
1634 1 + rotationY,
1635 faceTextureSlot6,
1636 textureSlotCount,
1637 color,
1638 ref vertices6.Array[count11 + 1]
1639 );
1641 x + 1,
1642 y,
1643 z + 1,
1644 1f,
1645 2 + rotationY,
1646 faceTextureSlot6,
1647 textureSlotCount,
1648 color,
1649 ref vertices6.Array[count11 + 2]
1650 );
1652 x,
1653 y,
1654 z + 1,
1655 1f,
1656 3 + rotationY,
1657 faceTextureSlot6,
1658 textureSlotCount,
1659 color,
1660 ref vertices6.Array[count11 + 3]
1661 );
1662 int count12 = indices6.Count;
1663 indices6.Count += 6;
1664 indices6.Array[count12] = count11;
1665 indices6.Array[count12 + 1] = count11 + 2;
1666 indices6.Array[count12 + 2] = count11 + 1;
1667 indices6.Array[count12 + 3] = count11 + 2;
1668 indices6.Array[count12 + 4] = count11;
1669 indices6.Array[count12 + 5] = count11 + 3;
1670 }
1671 }
1672
1673 public virtual void GenerateFlatVertices(Block block,
1674 int value,
1675 int x,
1676 int y,
1677 int z,
1678 int rotation,
1679 Color color,
1680 TerrainGeometrySubset[] subsetsByFace) {
1681 DynamicArray<TerrainVertex> vertices = subsetsByFace[4].Vertices;
1682 TerrainGeometryDynamicArray<int> indices = subsetsByFace[4].Indices;
1683 int faceTextureSlot = block.GetFaceTextureSlot(4, value);
1684 int textureSlotCount = block.GetTextureSlotCount(value);
1685 int count = vertices.Count;
1686 vertices.Count += 4;
1688 x,
1689 y + 1,
1690 z,
1691 0f,
1692 3 + rotation,
1693 faceTextureSlot,
1694 textureSlotCount,
1695 color,
1696 ref vertices.Array[count]
1697 );
1699 x + 1,
1700 y + 1,
1701 z,
1702 0f,
1703 2 + rotation,
1704 faceTextureSlot,
1705 textureSlotCount,
1706 color,
1707 ref vertices.Array[count + 1]
1708 );
1710 x + 1,
1711 y + 1,
1712 z + 1,
1713 0f,
1714 1 + rotation,
1715 faceTextureSlot,
1716 textureSlotCount,
1717 color,
1718 ref vertices.Array[count + 2]
1719 );
1721 x,
1722 y + 1,
1723 z + 1,
1724 0f,
1725 rotation,
1726 faceTextureSlot,
1727 textureSlotCount,
1728 color,
1729 ref vertices.Array[count + 3]
1730 );
1731 int count2 = indices.Count;
1732 indices.Count += 6;
1733 indices.Array[count2] = count;
1734 indices.Array[count2 + 1] = count + 1;
1735 indices.Array[count2 + 2] = count + 2;
1736 indices.Array[count2 + 3] = count + 2;
1737 indices.Array[count2 + 4] = count + 3;
1738 indices.Array[count2 + 5] = count;
1739 }
1740
1741 public virtual void GenerateMeshVertices(Block block,
1742 int x,
1743 int y,
1744 int z,
1745 BlockMesh blockMesh,
1746 Color color,
1747 Matrix? matrix,
1748 TerrainGeometrySubset subset) {
1749 DynamicArray<TerrainVertex> vertices = subset.Vertices;
1750 TerrainGeometryDynamicArray<int> indices = subset.Indices;
1751 int count = vertices.Count;
1752 int cellLightFast = Terrain.GetCellLightFast(x, y, z);
1753 float num = LightingManager.LightIntensityByLightValue[cellLightFast];
1754 vertices.Count += blockMesh.Vertices.Count;
1755 for (int i = 0; i < blockMesh.Vertices.Count; i++) {
1756 BlockMeshVertex blockMeshVertex = blockMesh.Vertices.Array[i];
1757 Vector3 vector = blockMeshVertex.Position;
1758 if (matrix.HasValue) {
1759 vector = Vector3.Transform(blockMeshVertex.Position, matrix.Value);
1760 }
1761 Color color2;
1762 if (blockMeshVertex.IsEmissive) {
1763 color2 = new Color(
1764 (byte)(color.R * blockMeshVertex.Color.R / 255),
1765 (byte)(color.G * blockMeshVertex.Color.G / 255),
1766 (byte)(color.B * blockMeshVertex.Color.B / 255)
1767 );
1768 }
1769 else {
1770 float num2 = num / 255f;
1771 color2 = new Color(
1772 (byte)(color.R * blockMeshVertex.Color.R * num2),
1773 (byte)(color.G * blockMeshVertex.Color.G * num2),
1774 (byte)(color.B * blockMeshVertex.Color.B * num2)
1775 );
1776 }
1778 x + vector.X,
1779 y + vector.Y,
1780 z + vector.Z,
1781 color2,
1782 blockMeshVertex.TextureCoordinates.X,
1783 blockMeshVertex.TextureCoordinates.Y,
1784 ref vertices.Array[count + i]
1785 );
1786 }
1787 if (blockMesh.Sides != null) {
1788 for (int j = 0; j < 6; j++) {
1789 Point3 point = CellFace.FaceToPoint3(j);
1790 int cellValueFastChunkExists = Terrain.GetCellValueFastChunkExists(x + point.X, y + point.Y, z + point.Z);
1791 m_visibleSides[j] = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFastChunkExists)]
1792 .IsFaceTransparent(SubsystemTerrain, CellFace.OppositeFace(j), cellValueFastChunkExists);
1793 }
1794 for (int k = 0; k < blockMesh.Indices.Count / 3; k++) {
1795 int num3 = blockMesh.Sides == null ? -1 : blockMesh.Sides.Array[k];
1796 if (num3 < 0
1797 || m_visibleSides[num3]) {
1798 indices.Add(blockMesh.Indices.Array[3 * k] + count);
1799 indices.Add(blockMesh.Indices.Array[3 * k + 1] + count);
1800 indices.Add(blockMesh.Indices.Array[3 * k + 2] + count);
1801 }
1802 }
1803 }
1804 else {
1805 for (int l = 0; l < blockMesh.Indices.Count; l++) {
1806 indices.Add(blockMesh.Indices.Array[l] + count);
1807 }
1808 }
1809 }
1810
1811 public virtual void GenerateShadedMeshVertices(Block block,
1812 int x,
1813 int y,
1814 int z,
1815 BlockMesh blockMesh,
1816 Color color,
1817 Matrix? matrix,
1818 int[] facesMap,
1819 TerrainGeometrySubset subset) {
1820 CalculateCornerLights(x, y, z);
1821 DynamicArray<TerrainVertex> vertices = subset.Vertices;
1822 TerrainGeometryDynamicArray<int> indices = subset.Indices;
1823 int count = vertices.Count;
1824 vertices.Count += blockMesh.Vertices.Count;
1825 for (int i = 0; i < blockMesh.Vertices.Count; i++) {
1826 BlockMeshVertex blockMeshVertex = blockMesh.Vertices.Array[i];
1827 Vector3 vector = blockMeshVertex.Position;
1828 if (matrix.HasValue) {
1829 vector = Vector3.Transform(vector, matrix.Value);
1830 }
1831 Color color2;
1832 if (blockMeshVertex.IsEmissive) {
1833 color2 = new Color(
1834 (byte)(color.R * blockMeshVertex.Color.R / 255),
1835 (byte)(color.G * blockMeshVertex.Color.G / 255),
1836 (byte)(color.B * blockMeshVertex.Color.B / 255)
1837 );
1838 }
1839 else {
1840 int face = facesMap != null ? facesMap[blockMeshVertex.Face] : blockMeshVertex.Face;
1841 float num = InterpolateCornerLights(face, vector) / 255f;
1842 color2 = new Color(
1843 (byte)(color.R * blockMeshVertex.Color.R * num),
1844 (byte)(color.G * blockMeshVertex.Color.G * num),
1845 (byte)(color.B * blockMeshVertex.Color.B * num)
1846 );
1847 }
1849 x + vector.X,
1850 y + vector.Y,
1851 z + vector.Z,
1852 color2,
1853 blockMeshVertex.TextureCoordinates.X,
1854 blockMeshVertex.TextureCoordinates.Y,
1855 ref vertices.Array[count + i]
1856 );
1857 }
1858 if (blockMesh.Sides != null) {
1859 for (int j = 0; j < 6; j++) {
1860 Point3 point = CellFace.FaceToPoint3(j);
1861 int cellValueFastChunkExists = Terrain.GetCellValueFastChunkExists(x + point.X, y + point.Y, z + point.Z);
1862 m_visibleSides[j] = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFastChunkExists)]
1863 .IsFaceTransparent(SubsystemTerrain, CellFace.OppositeFace(j), cellValueFastChunkExists);
1864 }
1865 for (int k = 0; k < blockMesh.Indices.Count / 3; k++) {
1866 int num2 = blockMesh.Sides == null ? -1 : blockMesh.Sides.Array[k];
1867 if (num2 < 0
1868 || m_visibleSides[facesMap != null ? facesMap[num2] : num2]) {
1869 indices.Add(blockMesh.Indices.Array[3 * k] + count);
1870 indices.Add(blockMesh.Indices.Array[3 * k + 1] + count);
1871 indices.Add(blockMesh.Indices.Array[3 * k + 2] + count);
1872 }
1873 }
1874 }
1875 else {
1876 for (int l = 0; l < blockMesh.Indices.Count; l++) {
1877 indices.Add(blockMesh.Indices.Array[l] + count);
1878 }
1879 }
1880 }
1881
1882 public virtual void GenerateWireVertices(int value,
1883 int x,
1884 int y,
1885 int z,
1886 int mountingFace,
1887 float centerBoxSize,
1888 Vector2 centerOffset,
1889 TerrainGeometrySubset subset) {
1890 if (SubsystemElectricity == null) {
1891 return;
1892 }
1893 Color color = WireBlock.WireColor;
1894 int num = Terrain.ExtractContents(value);
1895 if (num == 133) {
1896 int? color2 = WireBlock.GetColor(Terrain.ExtractData(value));
1897 if (color2.HasValue) {
1898 color = SubsystemPalette.GetColor(this, color2);
1899 }
1900 }
1901 int num2 = Terrain.ExtractLight(value);
1903 Vector3 v = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.5f * CellFace.FaceToVector3(mountingFace);
1904 Vector3 vector = CellFace.FaceToVector3(mountingFace);
1905 Vector2 v2 = new(0.9376f, 0.0001f);
1906 Vector2 v3 = new(0.03125f, 0.00550781237f);
1907 Point3 point = CellFace.FaceToPoint3(mountingFace);
1908 int cellContents = Terrain.GetCellContents(x - point.X, y - point.Y, z - point.Z);
1909 bool flag = cellContents == 2 || cellContents == 7 || cellContents == 8 || cellContents == 6 || cellContents == 62 || cellContents == 72;
1910 Vector3 v4 = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Top));
1911 Vector3 vector2 = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Left))
1912 * centerOffset.X
1913 + v4 * centerOffset.Y;
1914 int num4 = 0;
1915 m_tmpConnectionPaths.Clear();
1916 SubsystemElectricity.GetAllConnectedNeighbors(x, y, z, mountingFace, m_tmpConnectionPaths);
1917 foreach (ElectricConnectionPath tmpConnectionPath in m_tmpConnectionPaths) {
1918 if ((num4 & (1 << tmpConnectionPath.ConnectorFace)) == 0) {
1919 ElectricConnectorDirection? connectorDirection = SubsystemElectricity.GetConnectorDirection(
1920 mountingFace,
1921 0,
1922 tmpConnectionPath.ConnectorFace
1923 );
1924 if (!(centerOffset == Vector2.Zero)
1925 || connectorDirection != ElectricConnectorDirection.In) {
1926 num4 |= 1 << tmpConnectionPath.ConnectorFace;
1927 Color color3 = color;
1928 if (num != 133) {
1929 int cellValue = Terrain.GetCellValue(
1930 x + tmpConnectionPath.NeighborOffsetX,
1931 y + tmpConnectionPath.NeighborOffsetY,
1932 z + tmpConnectionPath.NeighborOffsetZ
1933 );
1934 if (Terrain.ExtractContents(cellValue) == 133) {
1935 int? color4 = WireBlock.GetColor(Terrain.ExtractData(cellValue));
1936 if (color4.HasValue) {
1937 color3 = SubsystemPalette.GetColor(this, color4);
1938 }
1939 }
1940 }
1941 Vector3 vector3 = connectorDirection != ElectricConnectorDirection.In
1942 ? CellFace.FaceToVector3(tmpConnectionPath.ConnectorFace)
1943 : -Vector3.Normalize(vector2);
1944 Vector3 vector4 = Vector3.Cross(vector, vector3);
1945 float s = centerBoxSize >= 0f ? MathUtils.Max(0.03125f, centerBoxSize / 2f) : centerBoxSize / 2f;
1946 float num5 = connectorDirection == ElectricConnectorDirection.In ? 0.03125f : 0.5f;
1947 float num6 = connectorDirection == ElectricConnectorDirection.In ? 0f :
1948 tmpConnectionPath.ConnectorFace == tmpConnectionPath.NeighborFace ? num5 + 0.03125f :
1949 tmpConnectionPath.ConnectorFace != CellFace.OppositeFace(tmpConnectionPath.NeighborFace) ? num5 : num5 - 0.03125f;
1950 Vector3 v5 = v - vector4 * 0.03125f + vector3 * s + vector2;
1951 Vector3 vector5 = v - vector4 * 0.03125f + vector3 * num5;
1952 Vector3 vector6 = v + vector4 * 0.03125f + vector3 * num5;
1953 Vector3 v6 = v + vector4 * 0.03125f + vector3 * s + vector2;
1954 Vector3 vector7 = v + vector * 0.03125f + vector3 * (centerBoxSize / 2f) + vector2;
1955 Vector3 vector8 = v + vector * 0.03125f + vector3 * num6;
1956 if (flag && centerBoxSize == 0f) {
1957 Vector3 vector9 = 0.25f * GetRandomWireOffset(0.5f * (v5 + v6), vector);
1958 v5 += vector9;
1959 v6 += vector9;
1960 vector7 += vector9;
1961 }
1962 Vector2 vector10 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 0f);
1963 Vector2 vector11 = v2 + v3 * new Vector2(num5 * 2f, 0f);
1964 Vector2 vector12 = v2 + v3 * new Vector2(num5 * 2f, 1f);
1965 Vector2 vector13 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 1f);
1966 Vector2 vector14 = v2 + v3 * new Vector2(centerBoxSize, 0.5f);
1967 Vector2 vector15 = v2 + v3 * new Vector2(num6 * 2f, 0.5f);
1968 int num7 = Terrain.ExtractLight(
1969 Terrain.GetCellValue(
1970 x + tmpConnectionPath.NeighborOffsetX,
1971 y + tmpConnectionPath.NeighborOffsetY,
1972 z + tmpConnectionPath.NeighborOffsetZ
1973 )
1974 );
1976 float num9 = 0.5f * (num3 + num8);
1977 float num10 = LightingManager.CalculateLighting(-vector4);
1978 float num11 = LightingManager.CalculateLighting(vector4);
1979 float num12 = LightingManager.CalculateLighting(vector);
1980 float num13 = num10 * num3;
1981 float num14 = num10 * num9;
1982 float num15 = num11 * num9;
1983 float num16 = num11 * num3;
1984 float num17 = num12 * num3;
1985 float num18 = num12 * num9;
1986 Color color5 = new((byte)(color3.R * num13), (byte)(color3.G * num13), (byte)(color3.B * num13));
1987 Color color6 = new((byte)(color3.R * num14), (byte)(color3.G * num14), (byte)(color3.B * num14));
1988 Color color7 = new((byte)(color3.R * num15), (byte)(color3.G * num15), (byte)(color3.B * num15));
1989 Color color8 = new((byte)(color3.R * num16), (byte)(color3.G * num16), (byte)(color3.B * num16));
1990 Color color9 = new((byte)(color3.R * num17), (byte)(color3.G * num17), (byte)(color3.B * num17));
1991 Color color10 = new((byte)(color3.R * num18), (byte)(color3.G * num18), (byte)(color3.B * num18));
1992 int count = subset.Vertices.Count;
1993 subset.Vertices.Count += 6;
1994 TerrainVertex[] array = subset.Vertices.Array;
1996 v5.X,
1997 v5.Y,
1998 v5.Z,
1999 color5,
2000 vector10.X,
2001 vector10.Y,
2002 ref array[count]
2003 );
2005 vector5.X,
2006 vector5.Y,
2007 vector5.Z,
2008 color6,
2009 vector11.X,
2010 vector11.Y,
2011 ref array[count + 1]
2012 );
2014 vector6.X,
2015 vector6.Y,
2016 vector6.Z,
2017 color7,
2018 vector12.X,
2019 vector12.Y,
2020 ref array[count + 2]
2021 );
2023 v6.X,
2024 v6.Y,
2025 v6.Z,
2026 color8,
2027 vector13.X,
2028 vector13.Y,
2029 ref array[count + 3]
2030 );
2032 vector7.X,
2033 vector7.Y,
2034 vector7.Z,
2035 color9,
2036 vector14.X,
2037 vector14.Y,
2038 ref array[count + 4]
2039 );
2041 vector8.X,
2042 vector8.Y,
2043 vector8.Z,
2044 color10,
2045 vector15.X,
2046 vector15.Y,
2047 ref array[count + 5]
2048 );
2049 int count2 = subset.Indices.Count;
2050 subset.Indices.Count += connectorDirection == ElectricConnectorDirection.In ? 15 : 12;
2051 int[] array2 = subset.Indices.Array;
2052 array2[count2] = count;
2053 array2[count2 + 1] = count + 5;
2054 array2[count2 + 2] = count + 1;
2055 array2[count2 + 3] = count + 5;
2056 array2[count2 + 4] = count;
2057 array2[count2 + 5] = count + 4;
2058 array2[count2 + 6] = count + 4;
2059 array2[count2 + 7] = count + 2;
2060 array2[count2 + 8] = count + 5;
2061 array2[count2 + 9] = count + 2;
2062 array2[count2 + 10] = count + 4;
2063 array2[count2 + 11] = count + 3;
2064 if (connectorDirection == ElectricConnectorDirection.In) {
2065 array2[count2 + 12] = count + 2;
2066 array2[count2 + 13] = count + 1;
2067 array2[count2 + 14] = count + 5;
2068 }
2069 }
2070 }
2071 }
2072 if (centerBoxSize != 0f
2073 || (num4 == 0 && num != 133)) {
2074 return;
2075 }
2076 for (int i = 0; i < 6; i++) {
2077 if (i != mountingFace
2078 && i != CellFace.OppositeFace(mountingFace)
2079 && (num4 & (1 << i)) == 0) {
2080 Vector3 vector16 = CellFace.FaceToVector3(i);
2081 Vector3 v7 = Vector3.Cross(vector, vector16);
2082 Vector3 v8 = v - v7 * 0.03125f + vector16 * 0.03125f;
2083 Vector3 v9 = v + v7 * 0.03125f + vector16 * 0.03125f;
2084 Vector3 vector17 = v + vector * 0.03125f;
2085 if (flag) {
2086 Vector3 vector18 = 0.25f * GetRandomWireOffset(0.5f * (v8 + v9), vector);
2087 v8 += vector18;
2088 v9 += vector18;
2089 vector17 += vector18;
2090 }
2091 Vector2 vector19 = v2 + v3 * new Vector2(0.0625f, 0f);
2092 Vector2 vector20 = v2 + v3 * new Vector2(0.0625f, 1f);
2093 Vector2 vector21 = v2 + v3 * new Vector2(0f, 0.5f);
2094 float num19 = LightingManager.CalculateLighting(vector16) * num3;
2095 float num20 = LightingManager.CalculateLighting(vector) * num3;
2096 Color color11 = new((byte)(color.R * num19), (byte)(color.G * num19), (byte)(color.B * num19));
2097 Color color12 = new((byte)(color.R * num20), (byte)(color.G * num20), (byte)(color.B * num20));
2098 int count3 = subset.Vertices.Count;
2099 subset.Vertices.Count += 3;
2100 TerrainVertex[] array3 = subset.Vertices.Array;
2102 v8.X,
2103 v8.Y,
2104 v8.Z,
2105 color11,
2106 vector19.X,
2107 vector19.Y,
2108 ref array3[count3]
2109 );
2111 v9.X,
2112 v9.Y,
2113 v9.Z,
2114 color11,
2115 vector20.X,
2116 vector20.Y,
2117 ref array3[count3 + 1]
2118 );
2120 vector17.X,
2121 vector17.Y,
2122 vector17.Z,
2123 color12,
2124 vector21.X,
2125 vector21.Y,
2126 ref array3[count3 + 2]
2127 );
2128 int count4 = subset.Indices.Count;
2129 subset.Indices.Count += 3;
2130 int[] array4 = subset.Indices.Array;
2131 array4[count4] = count3;
2132 array4[count4 + 1] = count3 + 2;
2133 array4[count4 + 2] = count3 + 1;
2134 }
2135 }
2136 }
2137
2138 public static void CalculateCubeVertexLight(int value, ref int light, ref int shadow) {
2139 int num = Terrain.ExtractContents(value);
2140 if (num == 0) {
2141 light = Math.Max(light, Terrain.ExtractLight(value));
2142 return;
2143 }
2144 light = Math.Max(light, Terrain.ExtractLight(value));
2145 shadow += BlocksManager.Blocks[num].GetShadowStrength(value);
2146 }
2147
2148 public static int CombineLightAndShadow(int light, int shadow) => MathUtils.Max(light - MathUtils.Max(shadow / 7, 0), 0);
2149
2150 public virtual int CalculateVertexLightFace0(int x, int y, int z) {
2151 int light = 0;
2152 int shadow = 0;
2153 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x - 1, z);
2154 int num = TerrainChunk.CalculateCellIndex((x - 1) & 0xF, y, z & 0xF);
2155 int cellValueFast = chunkAtCell.GetCellValueFast(num - 1);
2156 int cellValueFast2 = chunkAtCell.GetCellValueFast(num);
2157 CalculateCubeVertexLight(cellValueFast, ref light, ref shadow);
2158 CalculateCubeVertexLight(cellValueFast2, ref light, ref shadow);
2159 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x, z);
2160 int num2 = TerrainChunk.CalculateCellIndex(x & 0xF, y, z & 0xF);
2161 int cellValueFast3 = chunkAtCell2.GetCellValueFast(num2 - 1);
2162 int cellValueFast4 = chunkAtCell2.GetCellValueFast(num2);
2163 CalculateCubeVertexLight(cellValueFast3, ref light, ref shadow);
2164 CalculateCubeVertexLight(cellValueFast4, ref light, ref shadow);
2165 return CombineLightAndShadow(light, shadow);
2166 }
2167
2168 public virtual int CalculateVertexLightFace1(int x, int y, int z) {
2169 int light = 0;
2170 int shadow = 0;
2171 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z - 1);
2172 int num = TerrainChunk.CalculateCellIndex(x & 0xF, y, (z - 1) & 0xF);
2173 int cellValueFast = chunkAtCell.GetCellValueFast(num - 1);
2174 int cellValueFast2 = chunkAtCell.GetCellValueFast(num);
2175 CalculateCubeVertexLight(cellValueFast, ref light, ref shadow);
2176 CalculateCubeVertexLight(cellValueFast2, ref light, ref shadow);
2177 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x, z);
2178 int num2 = TerrainChunk.CalculateCellIndex(x & 0xF, y, z & 0xF);
2179 int cellValueFast3 = chunkAtCell2.GetCellValueFast(num2 - 1);
2180 int cellValueFast4 = chunkAtCell2.GetCellValueFast(num2);
2181 CalculateCubeVertexLight(cellValueFast3, ref light, ref shadow);
2182 CalculateCubeVertexLight(cellValueFast4, ref light, ref shadow);
2183 return CombineLightAndShadow(light, shadow);
2184 }
2185
2186 public virtual int CalculateVertexLightFace2(int x, int y, int z) {
2187 int light = 0;
2188 int shadow = 0;
2189 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x - 1, z - 1);
2190 int num = TerrainChunk.CalculateCellIndex((x - 1) & 0xF, y, (z - 1) & 0xF);
2191 int cellValueFast = chunkAtCell.GetCellValueFast(num - 1);
2192 int cellValueFast2 = chunkAtCell.GetCellValueFast(num);
2193 CalculateCubeVertexLight(cellValueFast, ref light, ref shadow);
2194 CalculateCubeVertexLight(cellValueFast2, ref light, ref shadow);
2195 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x, z - 1);
2196 int num2 = TerrainChunk.CalculateCellIndex(x & 0xF, y, (z - 1) & 0xF);
2197 int cellValueFast3 = chunkAtCell2.GetCellValueFast(num2 - 1);
2198 int cellValueFast4 = chunkAtCell2.GetCellValueFast(num2);
2199 CalculateCubeVertexLight(cellValueFast3, ref light, ref shadow);
2200 CalculateCubeVertexLight(cellValueFast4, ref light, ref shadow);
2201 return CombineLightAndShadow(light, shadow);
2202 }
2203
2204 public virtual int CalculateVertexLightFace3(int x, int y, int z) {
2205 int light = 0;
2206 int shadow = 0;
2207 TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x - 1, z - 1);
2208 int num = TerrainChunk.CalculateCellIndex((x - 1) & 0xF, y, (z - 1) & 0xF);
2209 int cellValueFast = chunkAtCell.GetCellValueFast(num - 1);
2210 int cellValueFast2 = chunkAtCell.GetCellValueFast(num);
2211 CalculateCubeVertexLight(cellValueFast, ref light, ref shadow);
2212 CalculateCubeVertexLight(cellValueFast2, ref light, ref shadow);
2213 TerrainChunk chunkAtCell2 = Terrain.GetChunkAtCell(x - 1, z);
2214 int num2 = TerrainChunk.CalculateCellIndex((x - 1) & 0xF, y, z & 0xF);
2215 int cellValueFast3 = chunkAtCell2.GetCellValueFast(num2 - 1);
2216 int cellValueFast4 = chunkAtCell2.GetCellValueFast(num2);
2217 CalculateCubeVertexLight(cellValueFast3, ref light, ref shadow);
2218 CalculateCubeVertexLight(cellValueFast4, ref light, ref shadow);
2219 return CombineLightAndShadow(light, shadow);
2220 }
2221
2222 public virtual int CalculateVertexLightFace4(int x, int y, int z) {
2223 int light = 0;
2224 int shadow = 0;
2225 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x - 1, y, z - 1), ref light, ref shadow);
2226 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x, y, z - 1), ref light, ref shadow);
2227 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x - 1, y, z), ref light, ref shadow);
2228 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x, y, z), ref light, ref shadow);
2229 return CombineLightAndShadow(light, shadow);
2230 }
2231
2232 public virtual int CalculateVertexLightFace5(int x, int y, int z) {
2233 int light = 0;
2234 int shadow = 0;
2235 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x - 1, y - 1, z - 1), ref light, ref shadow);
2236 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x, y - 1, z - 1), ref light, ref shadow);
2237 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x - 1, y - 1, z), ref light, ref shadow);
2238 CalculateCubeVertexLight(Terrain.GetCellValueFastChunkExists(x, y - 1, z), ref light, ref shadow);
2239 return CombineLightAndShadow(light, shadow);
2240 }
2241
2242 public virtual void SetupCubeVertexFace0(int x,
2243 int y,
2244 int z,
2245 float height,
2246 int corner,
2247 int textureSlot,
2248 int textureSlotCount,
2249 Color color,
2250 ref TerrainVertex vertex) {
2251 float y2 = y + height - 1f;
2252 int light = CalculateVertexLightFace0(x, y, z);
2254 x,
2255 y2,
2256 z,
2257 color,
2258 light,
2259 0,
2260 textureSlot,
2261 textureSlotCount,
2262 corner,
2263 ref vertex
2264 );
2265 }
2266
2267 public virtual void SetupCubeVertexFace1(int x,
2268 int y,
2269 int z,
2270 float height,
2271 int corner,
2272 int textureSlot,
2273 int textureSlotCount,
2274 Color color,
2275 ref TerrainVertex vertex) {
2276 float y2 = y + height - 1f;
2277 int light = CalculateVertexLightFace1(x, y, z);
2279 x,
2280 y2,
2281 z,
2282 color,
2283 light,
2284 1,
2285 textureSlot,
2286 textureSlotCount,
2287 corner,
2288 ref vertex
2289 );
2290 }
2291
2292 public virtual void SetupCubeVertexFace2(int x,
2293 int y,
2294 int z,
2295 float height,
2296 int corner,
2297 int textureSlot,
2298 int textureSlotCount,
2299 Color color,
2300 ref TerrainVertex vertex) {
2301 float y2 = y + height - 1f;
2302 int light = CalculateVertexLightFace2(x, y, z);
2304 x,
2305 y2,
2306 z,
2307 color,
2308 light,
2309 2,
2310 textureSlot,
2311 textureSlotCount,
2312 corner,
2313 ref vertex
2314 );
2315 }
2316
2317 public virtual void SetupCubeVertexFace3(int x,
2318 int y,
2319 int z,
2320 float height,
2321 int corner,
2322 int textureSlot,
2323 int textureSlotCount,
2324 Color color,
2325 ref TerrainVertex vertex) {
2326 float y2 = y + height - 1f;
2327 int light = CalculateVertexLightFace3(x, y, z);
2329 x,
2330 y2,
2331 z,
2332 color,
2333 light,
2334 3,
2335 textureSlot,
2336 textureSlotCount,
2337 corner,
2338 ref vertex
2339 );
2340 }
2341
2342 public virtual void SetupCubeVertexFace4(int x,
2343 int y,
2344 int z,
2345 float height,
2346 int corner,
2347 int textureSlot,
2348 int textureSlotCount,
2349 Color color,
2350 ref TerrainVertex vertex) {
2351 float y2 = y + height - 1f;
2352 int light = CalculateVertexLightFace4(x, y, z);
2354 x,
2355 y2,
2356 z,
2357 color,
2358 light,
2359 4,
2360 textureSlot,
2361 textureSlotCount,
2362 corner,
2363 ref vertex
2364 );
2365 }
2366
2367 public virtual void SetupCubeVertexFace5(int x,
2368 int y,
2369 int z,
2370 float height,
2371 int corner,
2372 int textureSlot,
2373 int textureSlotCount,
2374 Color color,
2375 ref TerrainVertex vertex) {
2376 float y2 = y + height - 1f;
2377 int light = CalculateVertexLightFace5(x, y, z);
2379 x,
2380 y2,
2381 z,
2382 color,
2383 light,
2384 5,
2385 textureSlot,
2386 textureSlotCount,
2387 corner,
2388 ref vertex
2389 );
2390 }
2391
2392 public static Vector3 GetRandomWireOffset(Vector3 position, Vector3 normal) {
2393 int hashCode = Vector3.Round(2f * position).GetHashCode();
2394 Vector3 result = default;
2395 result.X = normal.X == 0f ? (float)(double)(MathUtils.Hash((uint)hashCode) % 255u) / 255f - 0.5f : 0f;
2396 result.Y = normal.Y == 0f ? (float)(double)(MathUtils.Hash((uint)(hashCode + 1)) % 255u) / 255f - 0.5f : 0f;
2397 result.Z = normal.Z == 0f ? (float)(double)(MathUtils.Hash((uint)(hashCode + 2)) % 255u) / 255f - 0.5f : 0f;
2398 return result;
2399 }
2400
2401 public virtual void CalculateCornerLights(int x, int y, int z) {
2402 if (!(m_cornerLightsPosition == new Point3(x, y, z))) {
2403 m_cornerLightsPosition = new Point3(x, y, z);
2452 }
2453 }
2454
2455 public virtual float InterpolateCornerLights(int face, Vector3 position) {
2456 float x = position.X;
2457 float y = position.Y;
2458 float z = position.Z;
2459 float num = 1f - x;
2460 float num2 = 1f - y;
2461 float num3 = 1f - z;
2462 return m_cornerLightsByFace[face].L000 * num * num2 * num3
2463 + m_cornerLightsByFace[face].L001 * num * num2 * z
2464 + m_cornerLightsByFace[face].L010 * num * y * num3
2465 + m_cornerLightsByFace[face].L011 * num * y * z
2466 + m_cornerLightsByFace[face].L100 * x * num2 * num3
2467 + m_cornerLightsByFace[face].L101 * x * num2 * z
2468 + m_cornerLightsByFace[face].L110 * x * y * num3
2469 + m_cornerLightsByFace[face].L111 * x * y * z;
2470 }
2471 }
2472}
Engine.Color Color
Engine.Vector3 Vector3
static int Hash(int key)
static int Max(int x1, int x2)
static void SetupLitCornerVertex(float x, float y, float z, Color color, int textureSlot, int corner, ref TerrainVertex vertex)
virtual void SetupCubeVertexFace3(int x, int y, int z, float height, int corner, int textureSlot, int textureSlotCount, Color color, ref TerrainVertex vertex)
static Vector3 GetRandomWireOffset(Vector3 position, Vector3 normal)
DynamicArray< ElectricConnectionPath > m_tmpConnectionPaths
virtual void SetupCubeVertexFace2(int x, int y, int z, float height, int corner, int textureSlot, int textureSlotCount, Color color, ref TerrainVertex vertex)
static void CalculateCubeVertexLight(int value, ref int light, ref int shadow)
virtual void SetupCubeVertexFace4(int x, int y, int z, float height, int corner, int textureSlot, int textureSlotCount, Color color, ref TerrainVertex vertex)
static void SetupVertex(float x, float y, float z, Color color, float tx, float ty, ref TerrainVertex vertex)
virtual int CalculateVertexLightFace1(int x, int y, int z)
virtual int CalculateVertexLightFace0(int x, int y, int z)
virtual void GenerateShadedMeshVertices(Block block, int x, int y, int z, BlockMesh blockMesh, Color color, Matrix? matrix, int[] facesMap, TerrainGeometrySubset subset)
virtual void SetupCubeVertexFace5(int x, int y, int z, float height, int corner, int textureSlot, int textureSlotCount, Color color, ref TerrainVertex vertex)
virtual void GenerateCrossfaceVertices(Block block, int value, int x, int y, int z, Color color, int textureSlot, TerrainGeometrySubset subset)
virtual void GenerateMeshVertices(Block block, int x, int y, int z, BlockMesh blockMesh, Color color, Matrix? matrix, TerrainGeometrySubset subset)
virtual void CalculateCornerLights(int x, int y, int z)
virtual void GenerateWireVertices(int value, int x, int y, int z, int mountingFace, float centerBoxSize, Vector2 centerOffset, TerrainGeometrySubset subset)
virtual void GenerateCubeVertices(Block block, int value, int x, int y, int z, int rotationX, int rotationY, int rotationZ, Color color, TerrainGeometrySubset[] subsetsByFace)
virtual void GenerateCubeVertices(Block block, int value, int x, int y, int z, float height11, float height21, float height22, float height12, Color sideColor, Color topColor11, Color topColor21, Color topColor22, Color topColor12, int overrideTopTextureSlot, TerrainGeometrySubset[] subsetsByFace)
virtual float InterpolateCornerLights(int face, Vector3 position)
virtual int CalculateVertexLightFace4(int x, int y, int z)
virtual int CalculateVertexLightFace2(int x, int y, int z)
virtual int CalculateVertexLightFace5(int x, int y, int z)
BlockGeometryGenerator(Terrain terrain, SubsystemTerrain subsystemTerrain, SubsystemElectricity subsystemElectricity, SubsystemFurnitureBlockBehavior subsystemFurnitureBlockBehavior, SubsystemMetersBlockBehavior subsystemMetersBlockBehavior, SubsystemPalette subsystemPalette)
virtual void GenerateCubeVertices(Block block, int value, int x, int y, int z, Color color, TerrainGeometrySubset[] subsetsByFace)
SubsystemMetersBlockBehavior SubsystemMetersBlockBehavior
SubsystemFurnitureBlockBehavior SubsystemFurnitureBlockBehavior
static void SetupCornerVertex(float x, float y, float z, Color color, int light, int face, int textureSlot, int textureSlotCount, int corner, ref TerrainVertex vertex)
virtual int CalculateVertexLightFace3(int x, int y, int z)
virtual void GenerateFlatVertices(Block block, int value, int x, int y, int z, int rotation, Color color, TerrainGeometrySubset[] subsetsByFace)
virtual void SetupCubeVertexFace0(int x, int y, int z, float height, int corner, int textureSlot, int textureSlotCount, Color color, ref TerrainVertex vertex)
static void SetupLitCornerVertex(float x, float y, float z, Color color, int textureSlot, int textureSlotCount, int corner, ref TerrainVertex vertex)
virtual void SetupCubeVertexFace1(int x, int y, int z, float height, int corner, int textureSlot, int textureSlotCount, Color color, ref TerrainVertex vertex)
static int CombineLightAndShadow(int light, int shadow)
int BlockIndex
定义 Block.cs:6
virtual int GetTextureSlotCount(int value)
设置材质(正方形)单行格子(分割后每个材质)数,对放置后的方块无效
virtual bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
virtual int GetShadowStrength(int value)
bool GenerateFacesForSameNeighbors
virtual bool ShouldGenerateFace(SubsystemTerrain subsystemTerrain, int face, int value, int neighborValue, int x, int y, int z)
virtual int GetFaceTextureSlot(int face, int value)
DynamicArray< sbyte > Sides
DynamicArray< BlockMeshVertex > Vertices
DynamicArray< int > Indices
static readonly float[] LightIntensityByLightValue
static float CalculateLighting(Vector3 normal)
static readonly float[] LightIntensityByLightValueAndFace
static int CalculateCellIndex(int x, int y, int z)
virtual int GetCellValueFast(int index)
TerrainGeometryDynamicArray< TerrainVertex > Vertices
TerrainGeometryDynamicArray< int > Indices
static ? int GetColor(int data)
static readonly Color WireColor
static readonly Vector2 Zero
static Vector3 Round(Vector3 v)
static Vector3 Transform(Vector3 v, Matrix m)
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
override int GetHashCode()
static int OppositeFace(int face)
static Vector3 FaceToVector3(int face)
static Point3 FaceToPoint3(int face)