Revision a65604a7
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/examples/meshfile/FactoryCubit.java | ||
---|---|---|
835 | 835 |
meshes[5] = meshes[4].copy(true); |
836 | 836 |
meshes[5].setEffectAssociation(0,32,0); |
837 | 837 |
|
838 |
return new MeshJoined(meshes); |
|
839 |
} |
|
840 |
|
|
841 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
842 |
|
|
843 |
private float[] createVertices(int A, int B) |
|
844 |
{ |
|
845 |
float E = 0.5f / Math.max(A,B); |
|
846 |
return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E }; |
|
847 |
} |
|
848 |
|
|
849 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
850 |
|
|
851 |
MeshBase createCuboid(int[] dimensions) |
|
852 |
{ |
|
853 |
int X = dimensions[0]; |
|
854 |
int Y = dimensions[1]; |
|
855 |
int Z = dimensions[2]; |
|
856 |
|
|
857 |
float[] verticesXY = createVertices(X,Y); |
|
858 |
float[] verticesXZ = createVertices(X,Z); |
|
859 |
float[] verticesYZ = createVertices(Z,Y); |
|
860 |
|
|
861 |
float defHeight = 0.048f; |
|
862 |
|
|
863 |
float[] bandsX = computeBands( defHeight/X,65,0.25f,0.5f,5); |
|
864 |
float[] bandsY = computeBands( defHeight/Y,65,0.25f,0.5f,5); |
|
865 |
float[] bandsZ = computeBands( defHeight/Z,65,0.25f,0.5f,5); |
|
866 |
|
|
867 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
868 |
|
|
869 |
meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2); |
|
870 |
meshes[0].setEffectAssociation(0,1,0); |
|
871 |
meshes[1] = meshes[0].copy(true); |
|
872 |
meshes[1].setEffectAssociation(0,2,0); |
|
873 |
meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2); |
|
874 |
meshes[2].setEffectAssociation(0,4,0); |
|
875 |
meshes[3] = meshes[2].copy(true); |
|
876 |
meshes[3].setEffectAssociation(0,8,0); |
|
877 |
meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2); |
|
878 |
meshes[4].setEffectAssociation(0,16,0); |
|
879 |
meshes[5] = meshes[4].copy(true); |
|
880 |
meshes[5].setEffectAssociation(0,32,0); |
|
881 |
|
|
882 |
|
|
838 | 883 |
return new MeshJoined(meshes); |
839 | 884 |
} |
840 | 885 |
|
... | ... | |
1494 | 1539 |
return effect; |
1495 | 1540 |
} |
1496 | 1541 |
|
1542 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1543 |
|
|
1544 |
VertexEffect[] createCuboidEffects(int[] dimensions) |
|
1545 |
{ |
|
1546 |
float X = dimensions[0]; |
|
1547 |
float Y = dimensions[1]; |
|
1548 |
float Z = dimensions[2]; |
|
1549 |
|
|
1550 |
float MAX_XY = Math.max(X,Y); |
|
1551 |
float MAX_XZ = Math.max(X,Z); |
|
1552 |
float MAX_YZ = Math.max(Z,Y); |
|
1553 |
|
|
1554 |
Static1D angle = new Static1D(90); |
|
1555 |
Static3D move = new Static3D( 0.0f, 0.0f, 0.5f); |
|
1556 |
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f); |
|
1557 |
Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f); |
|
1558 |
Static3D center= new Static3D( 0.0f, 0.0f, 0.0f); |
|
1559 |
|
|
1560 |
Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z); |
|
1561 |
Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z); |
|
1562 |
Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ); |
|
1563 |
Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ); |
|
1564 |
Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ); |
|
1565 |
Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ); |
|
1566 |
|
|
1567 |
VertexEffect[] effect = new VertexEffect[9]; |
|
1568 |
|
|
1569 |
effect[0] = new VertexEffectMove(move); |
|
1570 |
effect[1] = new VertexEffectRotate(angle, axisX, center); |
|
1571 |
effect[2] = new VertexEffectRotate(angle, axisY, center); |
|
1572 |
effect[3] = new VertexEffectScale(scale3); |
|
1573 |
effect[4] = new VertexEffectScale(scale4); |
|
1574 |
effect[5] = new VertexEffectScale(scale5); |
|
1575 |
effect[6] = new VertexEffectScale(scale6); |
|
1576 |
effect[7] = new VertexEffectScale(scale7); |
|
1577 |
effect[8] = new VertexEffectScale(scale8); |
|
1578 |
|
|
1579 |
effect[1].setMeshAssociation(12,-1); // meshes 2,3 |
|
1580 |
effect[2].setMeshAssociation( 3,-1); // meshes 0,1 |
|
1581 |
effect[3].setMeshAssociation(16,-1); // mesh 4 |
|
1582 |
effect[4].setMeshAssociation(32,-1); // mesh 5 |
|
1583 |
effect[5].setMeshAssociation( 8,-1); // mesh 3 |
|
1584 |
effect[6].setMeshAssociation( 4,-1); // mesh 2 |
|
1585 |
effect[7].setMeshAssociation( 1,-1); // mesh 0 |
|
1586 |
effect[8].setMeshAssociation( 2,-1); // mesh 1 |
|
1587 |
|
|
1588 |
return effect; |
|
1589 |
} |
|
1590 |
|
|
1497 | 1591 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1498 | 1592 |
// OBJECTS |
1499 | 1593 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1910 | 2004 |
|
1911 | 2005 |
//mesh.mergeEffComponents(); |
1912 | 2006 |
|
2007 |
return mesh; |
|
2008 |
} |
|
2009 |
|
|
2010 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2011 |
|
|
2012 |
MeshBase createCuboidMesh(int[] dimensions) |
|
2013 |
{ |
|
2014 |
MeshBase mesh = createCuboid(dimensions); |
|
2015 |
VertexEffect[] effects = createCuboidEffects(dimensions); |
|
2016 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
2017 |
|
|
2018 |
// mesh.mergeEffComponents(); |
|
2019 |
|
|
1913 | 2020 |
return mesh; |
1914 | 2021 |
} |
1915 | 2022 |
} |
Also available in: Unified diff
Beginnings of support for bandaged versions of the 3x3 cube.