Revision b2c77ec3
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java | ||
---|---|---|
82 | 82 |
|
83 | 83 |
} |
84 | 84 |
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public static FactoryCubit getInstance() |
|
88 |
{ |
|
89 |
if( mThis==null ) mThis = new FactoryCubit(); |
|
90 |
|
|
91 |
return mThis; |
|
92 |
} |
|
93 |
|
|
94 | 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
95 | 86 |
// H - height of the band in the middle |
96 | 87 |
// alpha - angle of the edge [0,90] |
... | ... | |
695 | 686 |
} |
696 | 687 |
|
697 | 688 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
698 |
// PUBLIC |
|
699 | 689 |
|
700 |
public float[] computeBands(float H, int alpha, float dist, float K, int N)
|
|
690 |
private float[] computeBands(float H, int alpha, float dist, float K, int N)
|
|
701 | 691 |
{ |
702 | 692 |
float[] bands = new float[2*N]; |
703 | 693 |
|
... | ... | |
748 | 738 |
|
749 | 739 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
750 | 740 |
|
751 |
public void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
|
|
741 |
private void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
|
|
752 | 742 |
{ |
753 | 743 |
Static4D reg= new Static4D(0,0,0,regionRadius); |
754 | 744 |
|
... | ... | |
769 | 759 |
|
770 | 760 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
771 | 761 |
|
762 |
private void computeConvexityCenter(float[] out, float[] in, FaceTransform ft) |
|
763 |
{ |
|
764 |
if( in==null ) |
|
765 |
{ |
|
766 |
out[0] = out[1] = 0.0f; |
|
767 |
} |
|
768 |
else |
|
769 |
{ |
|
770 |
out[0] = in[0] - ft.vx; |
|
771 |
out[1] = in[1] - ft.vy; |
|
772 |
out[2] = in[2] - ft.vz; |
|
773 |
out[3] = 1.0f; |
|
774 |
|
|
775 |
mQuat1[0] =-ft.qx; |
|
776 |
mQuat1[1] =-ft.qy; |
|
777 |
mQuat1[2] =-ft.qz; |
|
778 |
mQuat1[3] = ft.qw; |
|
779 |
|
|
780 |
mQuat2[0] = -mQuat1[0]; |
|
781 |
mQuat2[1] = -mQuat1[1]; |
|
782 |
mQuat2[2] = -mQuat1[2]; |
|
783 |
mQuat2[3] = +mQuat1[3]; |
|
784 |
|
|
785 |
quatMultiply(mQuat1, out , mQuat3); |
|
786 |
quatMultiply(mQuat3, mQuat2, out ); |
|
787 |
|
|
788 |
out[0] /= ft.scale; |
|
789 |
out[1] /= ft.scale; |
|
790 |
out[2] /= ft.scale; |
|
791 |
} |
|
792 |
} |
|
793 |
|
|
794 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
795 |
|
|
796 |
private void changeStickerPointers(int[][] table, int oldPointer, int newPointer) |
|
797 |
{ |
|
798 |
int len = table.length; |
|
799 |
|
|
800 |
for(int i=0; i<len; i++) |
|
801 |
{ |
|
802 |
int lenInner = table[i].length; |
|
803 |
|
|
804 |
for(int j=0; j<lenInner; j++) |
|
805 |
if( table[i][j]==oldPointer ) table[i][j] = newPointer; |
|
806 |
} |
|
807 |
} |
|
808 |
|
|
809 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
810 |
// INTERNAL API |
|
811 |
|
|
772 | 812 |
public int printStickerCoords() |
773 | 813 |
{ |
774 | 814 |
int stickers = mStickerCoords.size(); |
... | ... | |
824 | 864 |
} |
825 | 865 |
|
826 | 866 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
867 |
// PUBLIC API |
|
827 | 868 |
|
828 |
public void clear() |
|
829 |
{ |
|
830 |
mStickerCoords.clear(); |
|
831 |
mNewFaceTransf.clear(); |
|
832 |
mOldFaceTransf.clear(); |
|
833 |
} |
|
834 |
|
|
835 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
836 |
|
|
837 |
public void createNewFaceTransform( final float[][] vertices, final int[][] indexes, int outer) |
|
838 |
{ |
|
839 |
FaceTransform ft; |
|
840 |
int numNew = mNewFaceTransf.size(); |
|
841 |
|
|
842 |
for(int i=0; i<numNew; i++) |
|
843 |
{ |
|
844 |
ft = mNewFaceTransf.remove(0); |
|
845 |
mOldFaceTransf.add(ft); |
|
846 |
} |
|
847 |
|
|
848 |
int numFaces = indexes.length; |
|
849 |
int numOld = mOldFaceTransf.size(); |
|
850 |
|
|
851 |
for (int face=0; face<numFaces; face++) |
|
852 |
{ |
|
853 |
boolean collapsed = false; |
|
854 |
boolean isOuter = face<outer; |
|
855 |
|
|
856 |
float[][] vert = constructVert(vertices, indexes[face]); |
|
857 |
FaceTransform newT = constructNewTransform(vert,isOuter,face,numFaces); |
|
858 |
|
|
859 |
for (int old=0; !collapsed && old<numOld; old++) |
|
860 |
{ |
|
861 |
ft = mOldFaceTransf.get(old); |
|
862 |
if (successfullyCollapsedStickers(newT, ft)) collapsed = true; |
|
863 |
} |
|
864 |
|
|
865 |
for (int pre=0; !collapsed && pre<face; pre++) |
|
866 |
{ |
|
867 |
ft = mNewFaceTransf.get(pre); |
|
868 |
if (successfullyCollapsedStickers(newT, ft)) collapsed = true; |
|
869 |
} |
|
870 |
|
|
871 |
mNewFaceTransf.add(newT); |
|
872 |
} |
|
873 |
} |
|
874 |
|
|
875 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
876 |
|
|
877 |
public void createNewFaceTransform(final ObjectShape shape) |
|
878 |
{ |
|
879 |
float[][] vertices = shape.getVertices(); |
|
880 |
int[][] indices = shape.getVertIndices(); |
|
881 |
int outer = shape.getNumOutside(); |
|
882 |
createNewFaceTransform(vertices,indices,outer); |
|
883 |
} |
|
884 |
|
|
885 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
886 |
|
|
887 |
private void computeConvexityCenter(float[] out, float[] in, FaceTransform ft) |
|
869 |
public static FactoryCubit getInstance() |
|
888 | 870 |
{ |
889 |
if( in==null ) |
|
890 |
{ |
|
891 |
out[0] = out[1] = 0.0f; |
|
892 |
} |
|
893 |
else |
|
894 |
{ |
|
895 |
out[0] = in[0] - ft.vx; |
|
896 |
out[1] = in[1] - ft.vy; |
|
897 |
out[2] = in[2] - ft.vz; |
|
898 |
out[3] = 1.0f; |
|
899 |
|
|
900 |
mQuat1[0] =-ft.qx; |
|
901 |
mQuat1[1] =-ft.qy; |
|
902 |
mQuat1[2] =-ft.qz; |
|
903 |
mQuat1[3] = ft.qw; |
|
904 |
|
|
905 |
mQuat2[0] = -mQuat1[0]; |
|
906 |
mQuat2[1] = -mQuat1[1]; |
|
907 |
mQuat2[2] = -mQuat1[2]; |
|
908 |
mQuat2[3] = +mQuat1[3]; |
|
909 |
|
|
910 |
quatMultiply(mQuat1, out , mQuat3); |
|
911 |
quatMultiply(mQuat3, mQuat2, out ); |
|
871 |
if( mThis==null ) mThis = new FactoryCubit(); |
|
912 | 872 |
|
913 |
out[0] /= ft.scale; |
|
914 |
out[1] /= ft.scale; |
|
915 |
out[2] /= ft.scale; |
|
916 |
} |
|
873 |
return mThis; |
|
917 | 874 |
} |
918 | 875 |
|
919 | 876 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
920 | 877 |
|
921 |
public float[][] getOuterStickerCoords()
|
|
878 |
public float[] getOuterStickerScales()
|
|
922 | 879 |
{ |
923 | 880 |
int index=0,num=0,len = mStickerCoords.size(); |
924 | 881 |
|
... | ... | |
926 | 883 |
|
927 | 884 |
if( num>0 ) |
928 | 885 |
{ |
929 |
float[][] coords = new float[num][];
|
|
886 |
float[] scales = new float[num];
|
|
930 | 887 |
|
931 | 888 |
for(int i=0; i<len; i++) |
932 | 889 |
{ |
933 | 890 |
StickerCoords sticker = mStickerCoords.get(i); |
934 |
if( sticker.outer ) coords[index++] = sticker.vertices;
|
|
891 |
if( sticker.outer ) scales[index++] = sticker.scale;
|
|
935 | 892 |
} |
936 | 893 |
|
937 |
return coords;
|
|
894 |
return scales;
|
|
938 | 895 |
} |
939 | 896 |
|
940 | 897 |
return null; |
... | ... | |
942 | 899 |
|
943 | 900 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
944 | 901 |
|
945 |
public float[] getOuterStickerScales()
|
|
902 |
public float[][] getOuterStickerCoords()
|
|
946 | 903 |
{ |
947 | 904 |
int index=0,num=0,len = mStickerCoords.size(); |
948 | 905 |
|
... | ... | |
950 | 907 |
|
951 | 908 |
if( num>0 ) |
952 | 909 |
{ |
953 |
float[] scales = new float[num];
|
|
910 |
float[][] coords = new float[num][];
|
|
954 | 911 |
|
955 | 912 |
for(int i=0; i<len; i++) |
956 | 913 |
{ |
957 | 914 |
StickerCoords sticker = mStickerCoords.get(i); |
958 |
if( sticker.outer ) scales[index++] = sticker.scale;
|
|
915 |
if( sticker.outer ) coords[index++] = sticker.vertices;
|
|
959 | 916 |
} |
960 | 917 |
|
961 |
return scales;
|
|
918 |
return coords;
|
|
962 | 919 |
} |
963 | 920 |
|
964 | 921 |
return null; |
965 | 922 |
} |
966 | 923 |
|
967 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
968 |
|
|
969 |
private void changeStickerPointers(int[][] table, int oldPointer, int newPointer) |
|
970 |
{ |
|
971 |
int len = table.length; |
|
972 |
|
|
973 |
for(int i=0; i<len; i++) |
|
974 |
{ |
|
975 |
int lenInner = table[i].length; |
|
976 |
|
|
977 |
for(int j=0; j<lenInner; j++) |
|
978 |
if( table[i][j]==oldPointer ) table[i][j] = newPointer; |
|
979 |
} |
|
980 |
} |
|
981 |
|
|
982 | 924 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
983 | 925 |
|
984 | 926 |
public int[][] getStickerVariants() |
... | ... | |
1046 | 988 |
|
1047 | 989 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1048 | 990 |
|
1049 |
public MeshBase createRoundedSolid(final ObjectShape shape, final ObjectFaceShape face, int meshState, int numComponents)
|
|
991 |
public void clear()
|
|
1050 | 992 |
{ |
1051 |
float[][] vertices = shape.getVertices(); |
|
1052 |
int[][] vertIndexes = shape.getVertIndices(); |
|
1053 |
float[][] bands = face.getBands(); |
|
1054 |
int[] bandIndexes = face.getBandIndices(); |
|
1055 |
float[][] corners = face.getCorners(); |
|
1056 |
int[] cornerIndexes = face.getCornerIndices(); |
|
1057 |
float[][] centers = face.getCenters(); |
|
1058 |
int[] centerIndexes = face.getCenterIndices(); |
|
1059 |
float[] convexityCenter = face.getConvexityCenter(); |
|
1060 |
|
|
1061 |
return createRoundedSolid(vertices,vertIndexes,bands,bandIndexes,corners,cornerIndexes, |
|
1062 |
centers,centerIndexes,numComponents,convexityCenter, meshState); |
|
993 |
mStickerCoords.clear(); |
|
994 |
mNewFaceTransf.clear(); |
|
995 |
mOldFaceTransf.clear(); |
|
996 |
} |
|
997 |
|
|
998 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
999 |
|
|
1000 |
public void createNewFaceTransform(final ObjectShape shape) |
|
1001 |
{ |
|
1002 |
float[][] vertices = shape.getVertices(); |
|
1003 |
int[][] indices = shape.getVertIndices(); |
|
1004 |
int outer = shape.getNumOutside(); |
|
1005 |
FaceTransform ft; |
|
1006 |
int numNew = mNewFaceTransf.size(); |
|
1007 |
|
|
1008 |
for(int i=0; i<numNew; i++) |
|
1009 |
{ |
|
1010 |
ft = mNewFaceTransf.remove(0); |
|
1011 |
mOldFaceTransf.add(ft); |
|
1012 |
} |
|
1013 |
|
|
1014 |
int numFaces = indices.length; |
|
1015 |
int numOld = mOldFaceTransf.size(); |
|
1016 |
|
|
1017 |
for (int face=0; face<numFaces; face++) |
|
1018 |
{ |
|
1019 |
boolean collapsed = false; |
|
1020 |
boolean isOuter = face<outer; |
|
1021 |
|
|
1022 |
float[][] vert = constructVert(vertices, indices[face]); |
|
1023 |
FaceTransform newT = constructNewTransform(vert,isOuter,face,numFaces); |
|
1024 |
|
|
1025 |
for (int old=0; !collapsed && old<numOld; old++) |
|
1026 |
{ |
|
1027 |
ft = mOldFaceTransf.get(old); |
|
1028 |
if (successfullyCollapsedStickers(newT, ft)) collapsed = true; |
|
1029 |
} |
|
1030 |
|
|
1031 |
for (int pre=0; !collapsed && pre<face; pre++) |
|
1032 |
{ |
|
1033 |
ft = mNewFaceTransf.get(pre); |
|
1034 |
if (successfullyCollapsedStickers(newT, ft)) collapsed = true; |
|
1035 |
} |
|
1036 |
|
|
1037 |
mNewFaceTransf.add(newT); |
|
1038 |
} |
|
1063 | 1039 |
} |
1064 | 1040 |
|
1065 | 1041 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1066 | 1042 |
|
1067 |
public MeshBase createRoundedSolid(final float[][] vertices, final int[][] vertIndexes, |
|
1068 |
final float[][] bands , final int[] bandIndexes, |
|
1069 |
final float[][] corners , final int[] cornerIndexes, |
|
1070 |
final float[][] centers , final int[] centerIndexes, |
|
1071 |
final int numComponents , final float[] convexityCenter, |
|
1072 |
final int meshState ) |
|
1043 |
public MeshBase createRoundedSolid(final ObjectShape shape, final ObjectFaceShape faceShape, int meshState, int numComponents) |
|
1073 | 1044 |
{ |
1045 |
float[][] vertices = shape.getVertices(); |
|
1046 |
int[][] vertIndexes = shape.getVertIndices(); |
|
1047 |
float[][] bands = faceShape.getBands(); |
|
1048 |
int[] bandIndexes = faceShape.getBandIndices(); |
|
1049 |
float[][] corners = faceShape.getCorners(); |
|
1050 |
int[] cornerIndexes = faceShape.getCornerIndices(); |
|
1051 |
float[][] centers = faceShape.getCenters(); |
|
1052 |
int[] centerIndexes = faceShape.getCenterIndices(); |
|
1053 |
float[] convexityCenter = faceShape.getConvexityCenter(); |
|
1054 |
|
|
1074 | 1055 |
int numFaces = vertIndexes.length; |
1075 | 1056 |
float[] band, bandsComputed; |
1076 | 1057 |
MeshBase[] meshes = new MeshBase[numFaces]; |
Also available in: Unified diff
cleaning up.