Revision 6155e738
Added by Leszek Koltunski about 2 years ago
| src/main/java/org/distorted/objectlib/bandaged/FactoryBandaged.java | ||
|---|---|---|
| 15 | 15 |
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.REGION_SIZE; |
| 16 | 16 |
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.STRENGTH; |
| 17 | 17 |
|
| 18 |
import org.distorted.library.helpers.QuatHelper; |
|
| 18 | 19 |
import org.distorted.library.mesh.MeshBase; |
| 19 | 20 |
import org.distorted.library.type.Static3D; |
| 21 |
import org.distorted.library.type.Static4D; |
|
| 20 | 22 |
import org.distorted.objectlib.helpers.FactoryCubit; |
| 21 | 23 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
| 22 | 24 |
import org.distorted.objectlib.helpers.ObjectShape; |
| ... | ... | |
| 111 | 113 |
} |
| 112 | 114 |
} |
| 113 | 115 |
|
| 116 |
public static Static4D QUAT = new Static4D(0,0,0,1); |
|
| 117 |
|
|
| 114 | 118 |
private ArrayList<float[]> mTmpArray; |
| 119 |
private ArrayList<float[][]> mVertexArray; |
|
| 120 |
private BandagedElement[] mElements; |
|
| 121 |
private Static3D[] mNormals; |
|
| 115 | 122 |
private float[] mDist3D; |
| 116 | 123 |
private int[][] mFaceBelongsBitmap; |
| 117 | 124 |
private float[][] mDiaAxis; |
| 118 | 125 |
private float[][] mMinMax; |
| 119 |
|
|
| 120 |
BandagedElement[] mElements; |
|
| 121 |
ArrayList<float[][]> mVertexArray; |
|
| 122 |
|
|
| 123 |
int[][] mBandIndices; |
|
| 124 |
float[][][] mVertices; |
|
| 125 |
int[][][][] mIndices; |
|
| 126 |
float[][] mMove; |
|
| 127 |
int mNumElements; |
|
| 128 |
int mNumFaces; |
|
| 129 |
int mNumAxis; |
|
| 130 |
Static3D[] mNormals; |
|
| 131 |
|
|
| 132 |
int[] mNumLayers; |
|
| 126 |
private int mNumFaces; |
|
| 127 |
private int mNumElements; |
|
| 128 |
private float[][] mMove; |
|
| 129 |
private int[][][][] mIndices; |
|
| 130 |
private float[][][] mVertices; |
|
| 131 |
private int[][] mBandIndices; |
|
| 132 |
private int[] mNumLayers; |
|
| 133 |
private float[] mTmp; |
|
| 133 | 134 |
|
| 134 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 135 | 136 |
|
| ... | ... | |
| 141 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 142 | 143 |
|
| 143 | 144 |
abstract Static3D[] getNormals(); |
| 145 |
abstract Static4D getElementQuat(int element, int[] numLayers); |
|
| 144 | 146 |
abstract float[][] getDiameterAxis(); |
| 145 |
abstract float[] getDist3D(); |
|
| 146 |
abstract float[][] getBands(boolean iconMode); |
|
| 147 |
abstract int getElementVariant(float x, float y, float z); |
|
| 147 |
abstract float[] getDist3D(int[] numLayers);
|
|
| 148 |
abstract float[][] getBands(boolean iconMode, int[] numLayers);
|
|
| 149 |
abstract int getElementVariant(int[] numLayers, float x, float y, float z);
|
|
| 148 | 150 |
abstract int diameterMap(float diameter); |
| 149 |
abstract float[][] getVertices(int variant); |
|
| 150 |
abstract int[][] getIndices(int variant); |
|
| 151 |
abstract int getNumAxis(); |
|
| 151 |
abstract float[][] getVertices(int[] numLayers, int variant); |
|
| 152 |
abstract int[][] getIndices(int[] numLayers, int variant); |
|
| 152 | 153 |
|
| 153 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 154 | 155 |
|
| ... | ... | |
| 563 | 564 |
|
| 564 | 565 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 565 | 566 |
|
| 566 |
private float[] buildFaceVertices(float[][] vertices, int[] indices, float[] pos) |
|
| 567 |
private float[] buildFaceVertices(float[][] vertices, int[] indices, float[] pos, Static4D quat)
|
|
| 567 | 568 |
{
|
| 568 | 569 |
int num = indices.length; |
| 569 | 570 |
float[] ret = new float[3*num]; |
| ... | ... | |
| 571 | 572 |
for(int i=0; i<num; i++) |
| 572 | 573 |
{
|
| 573 | 574 |
float[] v = vertices[indices[i]]; |
| 574 |
ret[3*i ] = v[0] + pos[0]; |
|
| 575 |
ret[3*i+1] = v[1] + pos[1]; |
|
| 576 |
ret[3*i+2] = v[2] + pos[2]; |
|
| 575 |
QuatHelper.rotateVectorByQuat(mTmp,v[0],v[1],v[2],1,quat); |
|
| 576 |
|
|
| 577 |
ret[3*i ] = mTmp[0] + pos[0]; |
|
| 578 |
ret[3*i+1] = mTmp[1] + pos[1]; |
|
| 579 |
ret[3*i+2] = mTmp[2] + pos[2]; |
|
| 577 | 580 |
} |
| 578 | 581 |
|
| 579 | 582 |
return ret; |
| ... | ... | |
| 755 | 758 |
private void fillUpVertexArray() |
| 756 | 759 |
{
|
| 757 | 760 |
ArrayList<BandagedCubitFace> list = new ArrayList<>(); |
| 761 |
mTmp = new float[4]; |
|
| 758 | 762 |
|
| 759 | 763 |
for(int e=0; e<mNumElements; e++) |
| 760 | 764 |
{
|
| 761 |
int variant = mElements[e].getVariant(); |
|
| 762 |
float[][] verts = getVertices(variant); |
|
| 763 |
int[][] inds = getIndices(variant); |
|
| 764 |
float[] pos = mElements[e].getPos(); |
|
| 765 |
BandagedElement element = mElements[e]; |
|
| 766 |
int variant = element.getVariant(); |
|
| 767 |
float[] pos = element.getPos(); |
|
| 768 |
Static4D quat = element.getQuat(); |
|
| 769 |
|
|
| 770 |
float[][] verts = getVertices(mNumLayers,variant); |
|
| 771 |
int[][] inds = getIndices(mNumLayers,variant); |
|
| 765 | 772 |
|
| 766 | 773 |
for( int[] ind : inds) |
| 767 | 774 |
{
|
| 768 |
float[] vertices = buildFaceVertices(verts,ind,pos); |
|
| 775 |
float[] vertices = buildFaceVertices(verts,ind,pos,quat);
|
|
| 769 | 776 |
BandagedCubitFace face = new BandagedCubitFace(vertices); |
| 770 | 777 |
list.add(face); |
| 771 | 778 |
} |
| ... | ... | |
| 807 | 814 |
mNumLayers = numLayers; |
| 808 | 815 |
mNormals = getNormals(); |
| 809 | 816 |
mNumFaces = mNormals.length; |
| 810 |
mDist3D = getDist3D(); |
|
| 811 |
mNumAxis = getNumAxis(); |
|
| 817 |
mDist3D = getDist3D(mNumLayers); |
|
| 812 | 818 |
mDiaAxis = getDiameterAxis(); |
| 813 | 819 |
mMinMax = new float[mDiaAxis.length][2]; |
| 814 | 820 |
} |
| ... | ... | |
| 823 | 829 |
mElements = new BandagedElement[mNumElements]; |
| 824 | 830 |
for(int i=0; i<mNumElements; i++) |
| 825 | 831 |
{
|
| 826 |
int elementVariant = getElementVariant(pos[3*i],pos[3*i+1],pos[3*i+2]); |
|
| 827 |
mElements[i] = new BandagedElement(pos, 3*i, elementVariant); |
|
| 832 |
int elementVariant = getElementVariant(mNumLayers, pos[3*i],pos[3*i+1],pos[3*i+2]); |
|
| 833 |
Static4D quat = getElementQuat(i,mNumLayers); |
|
| 834 |
mElements[i] = new BandagedElement(pos, 3*i, elementVariant, quat); |
|
| 828 | 835 |
} |
| 829 | 836 |
|
| 830 | 837 |
fillUpVertexArray(); |
| ... | ... | |
| 842 | 849 |
|
| 843 | 850 |
public ObjectFaceShape createIrregularFaceShape(int variant, boolean iconMode) |
| 844 | 851 |
{
|
| 845 |
float[][] bands = getBands(iconMode); |
|
| 852 |
float[][] bands = getBands(iconMode, mNumLayers);
|
|
| 846 | 853 |
|
| 847 | 854 |
if( mBandIndices[variant]==null ) |
| 848 | 855 |
{
|
Also available in: Unified diff
progress with FactoryBandagedMegaminx.