├── .gitattributes
├── .gitignore
├── MANIFEST.MF
├── OpenAL64.dll
├── README.md
├── build.xml
├── lwjgl64.dll
├── master-application.jnlp
├── nbproject
├── assets-impl.xml
├── build-impl.xml
├── genfiles.properties
├── private
│ ├── private.properties
│ └── private.xml
├── project.properties
└── project.xml
├── src
└── mygame
│ └── Main.java
└── video-splash.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 |
--------------------------------------------------------------------------------
/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | X-Comment: Created with jMonkeyPlatform
2 |
--------------------------------------------------------------------------------
/OpenAL64.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/roboleary/GreedyMesh/e65162da8a6e439e064a07ceb5752f4e92715766/OpenAL64.dll
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Greedy meshing for complex voxel data
2 |
3 | This is a Java greedy meshing implementation based on the javascript implementation written by Mikola Lysenko and described in this blog post:
4 |
5 | [http://0fps.wordpress.com/2012/06/30/meshing-in-a-minecraft-game/](http://0fps.wordpress.com/2012/06/30/meshing-in-a-minecraft-game/ "http://0fps.wordpress.com/2012/06/30/meshing-in-a-minecraft-game/")
6 |
7 | The principal changes are:
8 |
9 | * Porting to Java
10 | * Modification in order to compare *voxel faces*, rather than voxels themselves
11 | * Modification to provide for comparison based on multiple attributes simultaneously
12 |
13 | Here is a video showing this implementation being used in a complex voxel engine, to produce greedy meshes in real time.
14 |
15 | [](https://www.youtube.com/watch?v=0OZxZZCea8I)
16 |
17 | This project is set up for use in JMonkey directly - but the meshing algorithm is fully commented and should be usable on any platform. The full implementation is contained in Main.java.
18 |
19 | Enjoy!
20 |
21 | ## Author
22 |
23 | Robert O'Leary - based on the work of [Mikola Lysenko](http://0fps.wordpress.com/)
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project BasicGameTemplate.
12 |
13 |
14 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/lwjgl64.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/roboleary/GreedyMesh/e65162da8a6e439e064a07ceb5752f4e92715766/lwjgl64.dll
--------------------------------------------------------------------------------
/master-application.jnlp:
--------------------------------------------------------------------------------
1 |
2 |
3 | ${APPLICATION.TITLE}
4 | ${APPLICATION.VENDOR}
5 |
6 | ${APPLICATION.DESC}
7 | ${APPLICATION.DESC.SHORT}
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/nbproject/assets-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/nbproject/build-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
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 | Must set src.dir
231 | Must set build.dir
232 | Must set dist.dir
233 | Must set build.classes.dir
234 | Must set dist.javadoc.dir
235 | Must set build.test.classes.dir
236 | Must set build.test.results.dir
237 | Must set build.classes.excludes
238 | Must set dist.jar
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 | Must set javac.includes
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 | No tests executed.
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 |
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 | Must set JVM to use for profiling in profiler.info.jvm
707 | Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
708 |
709 |
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 |
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 | Must select some files in the IDE or set javac.includes
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 |
957 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 | To run this application from the command line without Ant, try:
970 |
971 |
972 |
973 |
974 |
975 |
976 | java -cp "${run.classpath.with.dist.jar}" ${main.class}
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 |
994 |
995 |
996 |
997 |
998 |
999 |
1000 |
1001 | To run this application from the command line without Ant, try:
1002 |
1003 | java -jar "${dist.jar.resolved}"
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1028 |
1029 |
1030 |
1031 |
1032 | Must select one file in the IDE or set run.class
1033 |
1034 |
1035 |
1036 | Must select one file in the IDE or set run.class
1037 |
1038 |
1039 |
1044 |
1045 |
1046 |
1047 |
1048 |
1049 |
1050 |
1051 |
1052 |
1053 |
1054 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 |
1063 | Must select one file in the IDE or set debug.class
1064 |
1065 |
1066 |
1067 |
1068 | Must select one file in the IDE or set debug.class
1069 |
1070 |
1071 |
1072 |
1073 | Must set fix.includes
1074 |
1075 |
1076 |
1077 |
1078 |
1079 |
1080 |
1085 |
1088 |
1089 | This target only works when run from inside the NetBeans IDE.
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 | Must select one file in the IDE or set profile.class
1099 | This target only works when run from inside the NetBeans IDE.
1100 |
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 | This target only works when run from inside the NetBeans IDE.
1109 |
1110 |
1111 |
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 |
1120 |
1121 | This target only works when run from inside the NetBeans IDE.
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 |
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 |
1159 | Must select one file in the IDE or set run.class
1160 |
1161 |
1162 |
1163 |
1164 |
1165 | Must select some files in the IDE or set test.includes
1166 |
1167 |
1168 |
1169 |
1170 | Must select one file in the IDE or set run.class
1171 |
1172 |
1173 |
1174 |
1175 | Must select one file in the IDE or set applet.url
1176 |
1177 |
1178 |
1179 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 |
1192 |
1193 |
1194 |
1195 |
1196 |
1197 |
1198 |
1199 |
1200 |
1201 |
1202 |
1203 |
1204 |
1205 |
1206 |
1207 |
1208 |
1209 |
1210 |
1211 |
1212 |
1213 |
1214 |
1215 |
1216 |
1217 |
1218 |
1219 |
1220 |
1225 |
1226 |
1227 |
1228 |
1229 |
1230 |
1231 |
1232 |
1233 |
1234 |
1235 |
1236 |
1237 |
1238 |
1239 |
1240 |
1241 |
1242 |
1243 |
1244 |
1245 |
1246 |
1247 |
1248 |
1249 | Must select some files in the IDE or set javac.includes
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1264 |
1265 |
1266 |
1267 |
1268 |
1269 |
1270 |
1271 | Some tests failed; see details above.
1272 |
1273 |
1274 |
1275 |
1276 |
1277 |
1278 |
1279 |
1280 | Must select some files in the IDE or set test.includes
1281 |
1282 |
1283 |
1284 | Some tests failed; see details above.
1285 |
1286 |
1287 |
1288 | Must select some files in the IDE or set test.class
1289 | Must select some method in the IDE or set test.method
1290 |
1291 |
1292 |
1293 | Some tests failed; see details above.
1294 |
1295 |
1296 |
1301 |
1302 | Must select one file in the IDE or set test.class
1303 |
1304 |
1305 |
1306 | Must select one file in the IDE or set test.class
1307 | Must select some method in the IDE or set test.method
1308 |
1309 |
1310 |
1311 |
1312 |
1313 |
1314 |
1315 |
1316 |
1317 |
1318 |
1319 |
1324 |
1325 | Must select one file in the IDE or set applet.url
1326 |
1327 |
1328 |
1329 |
1330 |
1331 |
1332 |
1337 |
1338 | Must select one file in the IDE or set applet.url
1339 |
1340 |
1341 |
1342 |
1343 |
1344 |
1345 |
1346 |
1351 |
1352 |
1353 |
1354 |
1355 |
1356 |
1357 |
1358 |
1359 |
1360 |
1361 |
1362 |
1363 |
1364 |
1365 |
1366 |
1367 |
1368 |
1369 |
1370 |
1371 |
1372 |
1373 |
1374 |
1375 |
1376 |
1377 |
1378 |
1379 |
1380 |
1381 |
1382 |
1383 |
1384 |
1385 |
1386 |
1387 |
1388 |
1389 |
1390 |
1391 |
1392 |
1393 |
1394 |
1395 |
1396 |
--------------------------------------------------------------------------------
/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=94bf7c61
2 | build.xml.script.CRC32=79a29eb7
3 | build.xml.stylesheet.CRC32=958a1d3e@1.32.1.45
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=e7a6c31e
7 | nbproject/build-impl.xml.script.CRC32=5c06ba0d
8 | nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46
9 |
--------------------------------------------------------------------------------
/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | user.properties.file=C:\\Users\\asus\\AppData\\Roaming\\.jmonkeyplatform\\3.0\\build.properties
2 |
--------------------------------------------------------------------------------
/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | application.title=MyGame
2 | application.vendor=MyCompany
3 | assets.jar.name=assets.jar
4 | assets.excludes=**/*.j3odata,**/*.mesh,**/*.skeleton,**/*.mesh\.xml,**/*.skeleton\.xml,**/*.scene,**/*.material,**/*.obj,**/*.mtl,**/*.3ds,**/*.dae,**/*.blend,**/*.blend*[0-9]
5 | assets.folder.name=assets
6 | assets.compress=true
7 | build.classes.dir=${build.dir}/classes
8 | build.classes.excludes=**/*.java,**/*.form
9 | # This directory is removed when the project is cleaned:
10 | build.dir=build
11 | build.generated.dir=${build.dir}/generated
12 | build.generated.sources.dir=${build.dir}/generated-sources
13 | # Only compile against the classpath explicitly listed here:
14 | build.sysclasspath=ignore
15 | build.test.classes.dir=${build.dir}/test/classes
16 | build.test.results.dir=${build.dir}/test/results
17 | compile.on.save=true
18 | # Uncomment to specify the preferred debugger connection transport:
19 | #debug.transport=dt_socket
20 | debug.classpath=\
21 | ${run.classpath}
22 | debug.test.classpath=\
23 | ${run.test.classpath}
24 | # This directory is removed when the project is cleaned:
25 | dist.dir=dist
26 | dist.jar=${dist.dir}/${application.title}.jar
27 | dist.javadoc.dir=${dist.dir}/javadoc
28 | endorsed.classpath=
29 | excludes=
30 | includes=**
31 | jar.compress=false
32 | javac.classpath=\
33 | ${libs.jme3.classpath}:\
34 | ${libs.jme3-libraries.classpath}
35 | # Space-separated list of extra javac options
36 | javac.compilerargs=
37 | javac.deprecation=false
38 | javac.source=1.5
39 | javac.target=1.5
40 | javac.test.classpath=\
41 | ${javac.classpath}:\
42 | ${build.classes.dir}
43 | javadoc.additionalparam=
44 | javadoc.author=false
45 | javadoc.encoding=${source.encoding}
46 | javadoc.noindex=false
47 | javadoc.nonavbar=false
48 | javadoc.notree=false
49 | javadoc.private=false
50 | javadoc.splitindex=true
51 | javadoc.use=true
52 | javadoc.version=false
53 | javadoc.windowtitle=
54 | jaxbwiz.endorsed.dirs="${netbeans.home}/../ide12/modules/ext/jaxb/api"
55 | jnlp.codebase.type=local
56 | jnlp.descriptor=application
57 | jnlp.enabled=false
58 | jnlp.offline-allowed=false
59 | jnlp.signed=false
60 | main.class=mygame.Main
61 | meta.inf.dir=${src.dir}/META-INF
62 | manifest.file=MANIFEST.MF
63 | platform.active=default_platform
64 | run.classpath=\
65 | ${javac.classpath}:\
66 | ${build.classes.dir}:\
67 | ${assets.folder.name}
68 | # Space-separated list of JVM arguments used when running the project
69 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
70 | # or test-sys-prop.name=value to set system properties for unit tests):
71 | run.jvmargs=
72 | run.test.classpath=\
73 | ${javac.test.classpath}:\
74 | ${build.test.classes.dir}
75 | source.encoding=UTF-8
76 | src.dir=src
77 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.java.j2seproject
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | GreedyMesh
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/mygame/Main.java:
--------------------------------------------------------------------------------
1 | package mygame;
2 |
3 | import com.jme3.app.SimpleApplication;
4 | import com.jme3.material.Material;
5 | import com.jme3.math.Vector3f;
6 | import com.jme3.scene.Geometry;
7 | import com.jme3.scene.Mesh;
8 | import com.jme3.scene.VertexBuffer.Type;
9 | import com.jme3.system.AppSettings;
10 | import com.jme3.util.BufferUtils;
11 |
12 | /**
13 | * This is a Java greedy meshing implementation based on the javascript implementation
14 | * written by Mikola Lysenko and described in this blog post:
15 | *
16 | * http://0fps.wordpress.com/2012/06/30/meshing-in-a-minecraft-game/
17 | *
18 | * The principal changes are:
19 | *
20 | * - Porting to Java
21 | * - Modification in order to compare *voxel faces*, rather than voxels themselves
22 | * - Modification to provide for comparison based on multiple attributes simultaneously
23 | *
24 | * This class is ready to be used on the JMonkey platform - but the algorithm should be
25 | * usable in any case.
26 | *
27 | * @author Rob O'Leary
28 | */
29 | public class Main extends SimpleApplication {
30 |
31 | /*
32 | * In this test each voxel has a size of one world unit - in reality a voxel engine
33 | * might have larger voxels - and there's a multiplication of the vertex coordinates
34 | * below to account for this.
35 | */
36 | private static final int VOXEL_SIZE = 1;
37 |
38 | /*
39 | * These are the chunk dimensions - it may not be the case in every voxel engine that
40 | * the data is rendered in chunks - but this demo assumes so. Anyway the chunk size is
41 | * just used to populate the sample data array. Also, in reality the chunk size will likely
42 | * be larger - for example, in my voxel engine chunks are 16x16x16 - but the small size
43 | * here allows for a simple demostration.
44 | */
45 | private static final int CHUNK_WIDTH = 3;
46 | private static final int CHUNK_HEIGHT = 3;
47 |
48 | /*
49 | * This is a 3D array of sample data - I'm using voxel faces here because I'm returning
50 | * the same data for each face in this example - but calls to the getVoxelFace function below
51 | * will return variations on voxel data per face in a real engine. For example, in my system
52 | * each voxel has a type, temperature, humidity, etc - which are constant across all faces, and
53 | * then attributes like sunlight, artificial light which face per face or even per vertex.
54 | */
55 | private final VoxelFace [][][] voxels = new VoxelFace [CHUNK_WIDTH][CHUNK_HEIGHT][CHUNK_WIDTH];
56 |
57 | /*
58 | * These are just constants to keep track of which face we're dealing with - their actual
59 | * values are unimportantly - only that they're constant.
60 | */
61 | private static final int SOUTH = 0;
62 | private static final int NORTH = 1;
63 | private static final int EAST = 2;
64 | private static final int WEST = 3;
65 | private static final int TOP = 4;
66 | private static final int BOTTOM = 5;
67 |
68 | /**
69 | * This class is used to encapsulate all information about a single voxel face. Any number of attributes can be
70 | * included - and the equals function will be called in order to compare faces. This is important because it
71 | * allows different faces of the same voxel to be merged based on varying attributes.
72 | *
73 | * Each face can contain vertex data - for example, int[] sunlight, in order to compare vertex attributes.
74 | *
75 | * Since it's optimal to combine greedy meshing with face culling, I have included a "transparent" attribute here
76 | * and the mesher skips transparent voxel faces. The getVoxelData function below - or whatever it's equivalent
77 | * might be when this algorithm is used in a real engine - could set the transparent attribute on faces based
78 | * on whether they should be visible or not.
79 | */
80 | class VoxelFace {
81 |
82 | public boolean transparent;
83 | public int type;
84 | public int side;
85 |
86 | public boolean equals(final VoxelFace face) { return face.transparent == this.transparent && face.type == this.type; }
87 | }
88 |
89 | /**
90 | * This is just the main function used to start the demo on JMonkey.
91 | *
92 | * @param args
93 | */
94 | public static void main(String[] args) {
95 |
96 | final Main app = new Main();
97 | app.settings = new AppSettings(true);
98 | app.setShowSettings(false);
99 | app.settings.setResolution(1280, 720);
100 |
101 | app.start();
102 | }
103 |
104 | /**
105 | * This is an initialization function used here to set up the sample voxel data
106 | * and launch the greedy meshing.
107 | */
108 | @Override
109 | public void simpleInitApp() {
110 |
111 | VoxelFace face;
112 |
113 | for (int i = 0; i < CHUNK_WIDTH; i++) {
114 |
115 | for (int j = 0; j < CHUNK_HEIGHT; j++) {
116 |
117 | for (int k = 0; k < CHUNK_HEIGHT; k++) {
118 |
119 | if (i > CHUNK_WIDTH/2 && i < CHUNK_WIDTH*0.75 &&
120 | j > CHUNK_HEIGHT/2 && j < CHUNK_HEIGHT*0.75 &&
121 | k > CHUNK_HEIGHT/2 && k < CHUNK_HEIGHT*0.75) {
122 |
123 | /*
124 | * We add a set of voxels of type 1 at the top-right of the chunk.
125 | *
126 | */
127 | face = new VoxelFace();
128 | face.type = 1;
129 |
130 | /*
131 | * To see an example of face culling being used in combination with
132 | * greedy meshing, you could set the trasparent attribute to true.
133 | */
134 | // face.transparent = true;
135 |
136 | } else if (i == 0) {
137 |
138 | /*
139 | * We add a set of voxels of type 2 on the left of the chunk.
140 | */
141 | face = new VoxelFace();
142 | face.type = 2;
143 |
144 | } else {
145 |
146 | /*
147 | * And the rest are set to type 3.
148 | */
149 | face = new VoxelFace();
150 | face.type = 3;
151 | }
152 |
153 | voxels[i][j][k] = face;
154 | }
155 | }
156 | }
157 |
158 | /*
159 | * And now that the sample data is prepared, we launch the greedy meshing.
160 | */
161 | greedy();
162 | }
163 |
164 | /**
165 | *
166 | */
167 | void greedy() {
168 |
169 | /*
170 | * These are just working variables for the algorithm - almost all taken
171 | * directly from Mikola Lysenko's javascript implementation.
172 | */
173 | int i, j, k, l, w, h, u, v, n, side = 0;
174 |
175 | final int[] x = new int []{0,0,0};
176 | final int[] q = new int []{0,0,0};
177 | final int[] du = new int[]{0,0,0};
178 | final int[] dv = new int[]{0,0,0};
179 |
180 | /*
181 | * We create a mask - this will contain the groups of matching voxel faces
182 | * as we proceed through the chunk in 6 directions - once for each face.
183 | */
184 | final VoxelFace[] mask = new VoxelFace [CHUNK_WIDTH * CHUNK_HEIGHT];
185 |
186 | /*
187 | * These are just working variables to hold two faces during comparison.
188 | */
189 | VoxelFace voxelFace, voxelFace1;
190 |
191 | /**
192 | * We start with the lesser-spotted boolean for-loop (also known as the old flippy floppy).
193 | *
194 | * The variable backFace will be TRUE on the first iteration and FALSE on the second - this allows
195 | * us to track which direction the indices should run during creation of the quad.
196 | *
197 | * This loop runs twice, and the inner loop 3 times - totally 6 iterations - one for each
198 | * voxel face.
199 | */
200 | for (boolean backFace = true, b = false; b != backFace; backFace = backFace && b, b = !b) {
201 |
202 | /*
203 | * We sweep over the 3 dimensions - most of what follows is well described by Mikola Lysenko
204 | * in his post - and is ported from his Javascript implementation. Where this implementation
205 | * diverges, I've added commentary.
206 | */
207 | for(int d = 0; d < 3; d++) {
208 |
209 | u = (d + 1) % 3;
210 | v = (d + 2) % 3;
211 |
212 | x[0] = 0;
213 | x[1] = 0;
214 | x[2] = 0;
215 |
216 | q[0] = 0;
217 | q[1] = 0;
218 | q[2] = 0;
219 | q[d] = 1;
220 |
221 | /*
222 | * Here we're keeping track of the side that we're meshing.
223 | */
224 | if (d == 0) { side = backFace ? WEST : EAST; }
225 | else if (d == 1) { side = backFace ? BOTTOM : TOP; }
226 | else if (d == 2) { side = backFace ? SOUTH : NORTH; }
227 |
228 | /*
229 | * We move through the dimension from front to back
230 | */
231 | for(x[d] = -1; x[d] < CHUNK_WIDTH;) {
232 |
233 | /*
234 | * -------------------------------------------------------------------
235 | * We compute the mask
236 | * -------------------------------------------------------------------
237 | */
238 | n = 0;
239 |
240 | for(x[v] = 0; x[v] < CHUNK_HEIGHT; x[v]++) {
241 |
242 | for(x[u] = 0; x[u] < CHUNK_WIDTH; x[u]++) {
243 |
244 | /*
245 | * Here we retrieve two voxel faces for comparison.
246 | */
247 | voxelFace = (x[d] >= 0 ) ? getVoxelFace(x[0], x[1], x[2], side) : null;
248 | voxelFace1 = (x[d] < CHUNK_WIDTH - 1) ? getVoxelFace(x[0] + q[0], x[1] + q[1], x[2] + q[2], side) : null;
249 |
250 | /*
251 | * Note that we're using the equals function in the voxel face class here, which lets the faces
252 | * be compared based on any number of attributes.
253 | *
254 | * Also, we choose the face to add to the mask depending on whether we're moving through on a backface or not.
255 | */
256 | mask[n++] = ((voxelFace != null && voxelFace1 != null && voxelFace.equals(voxelFace1)))
257 | ? null
258 | : backFace ? voxelFace1 : voxelFace;
259 | }
260 | }
261 |
262 | x[d]++;
263 |
264 | /*
265 | * Now we generate the mesh for the mask
266 | */
267 | n = 0;
268 |
269 | for(j = 0; j < CHUNK_HEIGHT; j++) {
270 |
271 | for(i = 0; i < CHUNK_WIDTH;) {
272 |
273 | if(mask[n] != null) {
274 |
275 | /*
276 | * We compute the width
277 | */
278 | for(w = 1; i + w < CHUNK_WIDTH && mask[n + w] != null && mask[n + w].equals(mask[n]); w++) {}
279 |
280 | /*
281 | * Then we compute height
282 | */
283 | boolean done = false;
284 |
285 | for(h = 1; j + h < CHUNK_HEIGHT; h++) {
286 |
287 | for(k = 0; k < w; k++) {
288 |
289 | if(mask[n + k + h * CHUNK_WIDTH] == null || !mask[n + k + h * CHUNK_WIDTH].equals(mask[n])) { done = true; break; }
290 | }
291 |
292 | if(done) { break; }
293 | }
294 |
295 | /*
296 | * Here we check the "transparent" attribute in the VoxelFace class to ensure that we don't mesh
297 | * any culled faces.
298 | */
299 | if (!mask[n].transparent) {
300 | /*
301 | * Add quad
302 | */
303 | x[u] = i;
304 | x[v] = j;
305 |
306 | du[0] = 0;
307 | du[1] = 0;
308 | du[2] = 0;
309 | du[u] = w;
310 |
311 | dv[0] = 0;
312 | dv[1] = 0;
313 | dv[2] = 0;
314 | dv[v] = h;
315 |
316 | /*
317 | * And here we call the quad function in order to render a merged quad in the scene.
318 | *
319 | * We pass mask[n] to the function, which is an instance of the VoxelFace class containing
320 | * all the attributes of the face - which allows for variables to be passed to shaders - for
321 | * example lighting values used to create ambient occlusion.
322 | */
323 | quad(new Vector3f(x[0], x[1], x[2]),
324 | new Vector3f(x[0] + du[0], x[1] + du[1], x[2] + du[2]),
325 | new Vector3f(x[0] + du[0] + dv[0], x[1] + du[1] + dv[1], x[2] + du[2] + dv[2]),
326 | new Vector3f(x[0] + dv[0], x[1] + dv[1], x[2] + dv[2]),
327 | w,
328 | h,
329 | mask[n],
330 | backFace);
331 | }
332 |
333 | /*
334 | * We zero out the mask
335 | */
336 | for(l = 0; l < h; ++l) {
337 |
338 | for(k = 0; k < w; ++k) { mask[n + k + l * CHUNK_WIDTH] = null; }
339 | }
340 |
341 | /*
342 | * And then finally increment the counters and continue
343 | */
344 | i += w;
345 | n += w;
346 |
347 | } else {
348 |
349 | i++;
350 | n++;
351 | }
352 | }
353 | }
354 | }
355 | }
356 | }
357 | }
358 |
359 | /**
360 | * This function returns an instance of VoxelFace containing the attributes for
361 | * one side of a voxel. In this simple demo we just return a value from the
362 | * sample data array. However, in an actual voxel engine, this function would
363 | * check if the voxel face should be culled, and set per-face and per-vertex
364 | * values as well as voxel values in the returned instance.
365 | *
366 | * @param x
367 | * @param y
368 | * @param z
369 | * @param face
370 | * @return
371 | */
372 | VoxelFace getVoxelFace(final int x, final int y, final int z, final int side) {
373 |
374 | VoxelFace voxelFace = voxels[x][y][z];
375 |
376 | voxelFace.side = side;
377 |
378 | return voxelFace;
379 | }
380 |
381 | /**
382 | * This function renders a single quad in the scene. This quad may represent many adjacent voxel
383 | * faces - so in order to create the illusion of many faces, you might consider using a tiling
384 | * function in your voxel shader. For this reason I've included the quad width and height as parameters.
385 | *
386 | * For example, if your texture coordinates for a single voxel face were 0 - 1 on a given axis, they should now
387 | * be 0 - width or 0 - height. Then you can calculate the correct texture coordinate in your fragement
388 | * shader using coord.xy = fract(coord.xy).
389 | *
390 | *
391 | * @param bottomLeft
392 | * @param topLeft
393 | * @param topRight
394 | * @param bottomRight
395 | * @param width
396 | * @param height
397 | * @param voxel
398 | * @param backFace
399 | */
400 | void quad(final Vector3f bottomLeft,
401 | final Vector3f topLeft,
402 | final Vector3f topRight,
403 | final Vector3f bottomRight,
404 | final int width,
405 | final int height,
406 | final VoxelFace voxel,
407 | final boolean backFace) {
408 |
409 | final Vector3f [] vertices = new Vector3f[4];
410 |
411 | vertices[2] = topLeft.multLocal(VOXEL_SIZE);
412 | vertices[3] = topRight.multLocal(VOXEL_SIZE);
413 | vertices[0] = bottomLeft.multLocal(VOXEL_SIZE);
414 | vertices[1] = bottomRight.multLocal(VOXEL_SIZE);
415 |
416 | final int [] indexes = backFace ? new int[] { 2,0,1, 1,3,2 } : new int[]{ 2,3,1, 1,0,2 };
417 |
418 | final float[] colorArray = new float[4*4];
419 |
420 | for (int i = 0; i < colorArray.length; i+=4) {
421 |
422 | /*
423 | * Here I set different colors for quads depending on the "type" attribute, just
424 | * so that the different groups of voxels can be clearly seen.
425 | *
426 | */
427 | if (voxel.type == 1) {
428 |
429 | colorArray[i] = 1.0f;
430 | colorArray[i+1] = 0.0f;
431 | colorArray[i+2] = 0.0f;
432 | colorArray[i+3] = 1.0f;
433 |
434 | } else if (voxel.type == 2) {
435 |
436 | colorArray[i] = 0.0f;
437 | colorArray[i+1] = 1.0f;
438 | colorArray[i+2] = 0.0f;
439 | colorArray[i+3] = 1.0f;
440 |
441 | } else {
442 |
443 | colorArray[i] = 0.0f;
444 | colorArray[i+1] = 0.0f;
445 | colorArray[i+2] = 1.0f;
446 | colorArray[i+3] = 1.0f;
447 | }
448 | }
449 |
450 | Mesh mesh = new Mesh();
451 |
452 | mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
453 | mesh.setBuffer(Type.Color, 4, colorArray);
454 | mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));
455 | mesh.updateBound();
456 |
457 | Geometry geo = new Geometry("ColoredMesh", mesh);
458 | Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
459 | mat.setBoolean("VertexColor", true);
460 |
461 | /*
462 | * To see the actual rendered quads rather than the wireframe, just comment outthis line.
463 | */
464 | mat.getAdditionalRenderState().setWireframe(true);
465 |
466 | geo.setMaterial(mat);
467 |
468 | rootNode.attachChild(geo);
469 | }
470 | }
--------------------------------------------------------------------------------
/video-splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/roboleary/GreedyMesh/e65162da8a6e439e064a07ceb5752f4e92715766/video-splash.png
--------------------------------------------------------------------------------