Revision 7198e5c9
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/examples/meshfile/MeshFileActivity.java | ||
|---|---|---|
| 25 | 25 |
import android.view.View; |
| 26 | 26 |
import android.widget.AdapterView; |
| 27 | 27 |
import android.widget.ArrayAdapter; |
| 28 |
import android.widget.Button; |
|
| 29 |
import android.widget.LinearLayout; |
|
| 28 | 30 |
import android.widget.SeekBar; |
| 29 | 31 |
import android.widget.Spinner; |
| 30 | 32 |
import android.widget.TextView; |
| ... | ... | |
| 34 | 36 |
|
| 35 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | 38 |
|
| 37 |
public class MeshFileActivity extends Activity implements AdapterView.OnItemSelectedListener, SeekBar.OnSeekBarChangeListener |
|
| 39 |
public class MeshFileActivity extends Activity implements AdapterView.OnItemSelectedListener, |
|
| 40 |
SeekBar.OnSeekBarChangeListener, |
|
| 41 |
View.OnClickListener |
|
| 38 | 42 |
{
|
| 43 |
private LinearLayout mLayout; |
|
| 39 | 44 |
private int mResource; |
| 40 | 45 |
private String[] mNames = new String[] { "deferredjob",
|
| 41 | 46 |
"meshjoin" , |
| ... | ... | |
| 67 | 72 |
SeekBar barB = findViewById(R.id.meshfileScale); |
| 68 | 73 |
barB.setOnSeekBarChangeListener(this); |
| 69 | 74 |
barB.setProgress(50); |
| 75 |
|
|
| 76 |
mLayout = findViewById(R.id.meshfileComponentLayout); |
|
| 70 | 77 |
} |
| 71 | 78 |
|
| 72 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 121 | 128 |
byt.setText( String.format("%d", bytes ) );
|
| 122 | 129 |
ver.setText( String.format("%d", vertices) );
|
| 123 | 130 |
tim.setText( String.format("%d", time ) );
|
| 131 |
|
|
| 132 |
mLayout.removeAllViews(); |
|
| 133 |
|
|
| 134 |
int effComponentNum = renderer.getEffComponentNum(); |
|
| 135 |
|
|
| 136 |
for(int i=0; i<effComponentNum; i++) |
|
| 137 |
{
|
|
| 138 |
View compView = createComponentView(renderer,i); |
|
| 139 |
mLayout.addView(compView); |
|
| 140 |
} |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 144 |
|
|
| 145 |
private View createComponentView(MeshFileRenderer renderer, int component) |
|
| 146 |
{
|
|
| 147 |
View view = getLayoutInflater().inflate(R.layout.meshfilecomponent, null); |
|
| 148 |
|
|
| 149 |
TextView id = view.findViewById(R.id.meshfileComponentID); |
|
| 150 |
id.setText(String.valueOf(component)); |
|
| 151 |
|
|
| 152 |
int endIndex = renderer.getEndEffIndex(component); |
|
| 153 |
TextView index = view.findViewById(R.id.meshfileComponentText); |
|
| 154 |
index.setText(String.valueOf(endIndex)); |
|
| 155 |
|
|
| 156 |
Button butt = view.findViewById(R.id.meshfileComponentDisappear); |
|
| 157 |
butt.setId(component); |
|
| 158 |
butt.setOnClickListener(this); |
|
| 159 |
|
|
| 160 |
return view; |
|
| 124 | 161 |
} |
| 125 | 162 |
|
| 126 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 151 | 188 |
{
|
| 152 | 189 |
} |
| 153 | 190 |
|
| 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 192 |
|
|
| 193 |
@Override |
|
| 194 |
public void onClick(View v) |
|
| 195 |
{
|
|
| 196 |
int id = v.getId(); |
|
| 197 |
|
|
| 198 |
android.util.Log.e("act", "clicked: "+id);
|
|
| 199 |
} |
|
| 200 |
|
|
| 154 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 155 | 202 |
|
| 156 | 203 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
| src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java | ||
|---|---|---|
| 33 | 33 |
import org.distorted.library.main.DistortedLibrary; |
| 34 | 34 |
import org.distorted.library.main.DistortedScreen; |
| 35 | 35 |
import org.distorted.library.main.DistortedTexture; |
| 36 |
import org.distorted.library.mesh.MeshBase; |
|
| 37 | 36 |
import org.distorted.library.mesh.MeshFile; |
| 38 | 37 |
import org.distorted.library.type.DynamicQuat; |
| 39 | 38 |
import org.distorted.library.type.Static3D; |
| ... | ... | |
| 58 | 57 |
private DistortedEffects mEffects; |
| 59 | 58 |
private Static3D mScale; |
| 60 | 59 |
private long mTime; |
| 61 |
private int mBytes; |
|
| 62 |
private int mVertices; |
|
| 63 | 60 |
private float mCurrentScale; |
| 61 |
private MeshFile mMesh; |
|
| 64 | 62 |
|
| 65 | 63 |
Static4D mQuat1, mQuat2; |
| 66 | 64 |
int mScreenMin; |
| ... | ... | |
| 155 | 153 |
mTexture.setTexture( createTexture(resourceID) ); |
| 156 | 154 |
|
| 157 | 155 |
long t1 = System.currentTimeMillis(); |
| 158 |
MeshBase mesh = createMesh(resourceID);
|
|
| 156 |
createMesh(resourceID); |
|
| 159 | 157 |
long t2 = System.currentTimeMillis(); |
| 160 | 158 |
|
| 161 | 159 |
mTime = t2-t1; |
| 162 | 160 |
|
| 163 | 161 |
mScreen.detachAll(); |
| 164 |
mScreen.attach(mTexture,mEffects,mesh); |
|
| 162 |
mScreen.attach(mTexture,mEffects,mMesh);
|
|
| 165 | 163 |
} |
| 166 | 164 |
|
| 167 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 298 | 296 |
|
| 299 | 297 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 300 | 298 |
|
| 301 |
private MeshBase createMesh(int resourceID)
|
|
| 299 |
private void createMesh(int resourceID)
|
|
| 302 | 300 |
{
|
| 303 | 301 |
Context con = mView.getContext(); |
| 304 | 302 |
Resources res = con.getResources(); |
| 305 | 303 |
InputStream is = res.openRawResource(resourceID); |
| 306 | 304 |
DataInputStream dos = new DataInputStream(is); |
| 307 |
MeshFile mesh = new MeshFile(dos); |
|
| 308 |
|
|
| 309 |
mBytes = mesh.getNumBytes(); |
|
| 310 |
mVertices = mesh.getNumVertices(); |
|
| 305 |
mMesh = new MeshFile(dos); |
|
| 311 | 306 |
|
| 312 | 307 |
try |
| 313 | 308 |
{
|
| ... | ... | |
| 317 | 312 |
{
|
| 318 | 313 |
android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
|
| 319 | 314 |
} |
| 320 |
|
|
| 321 |
return mesh; |
|
| 322 | 315 |
} |
| 323 | 316 |
|
| 324 | 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 332 | 325 |
|
| 333 | 326 |
int getBytes() |
| 334 | 327 |
{
|
| 335 |
return mBytes;
|
|
| 328 |
return mMesh.getNumBytes();
|
|
| 336 | 329 |
} |
| 337 | 330 |
|
| 338 | 331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 339 | 332 |
|
| 340 | 333 |
int getVertices() |
| 341 | 334 |
{
|
| 342 |
return mVertices; |
|
| 335 |
return mMesh.getNumVertices(); |
|
| 336 |
} |
|
| 337 |
|
|
| 338 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 339 |
|
|
| 340 |
int getEndEffIndex(int component) |
|
| 341 |
{
|
|
| 342 |
return mMesh.getLastVertexEff(component); |
|
| 343 |
} |
|
| 344 |
|
|
| 345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 346 |
|
|
| 347 |
int getEndTexIndex(int component) |
|
| 348 |
{
|
|
| 349 |
return mMesh.getLastVertexTex(component); |
|
| 350 |
} |
|
| 351 |
|
|
| 352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 353 |
|
|
| 354 |
int getEffComponentNum() |
|
| 355 |
{
|
|
| 356 |
return mMesh.numEffComponents(); |
|
| 357 |
} |
|
| 358 |
|
|
| 359 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 360 |
|
|
| 361 |
int getTexComponentNum() |
|
| 362 |
{
|
|
| 363 |
return mMesh.numTexComponents(); |
|
| 343 | 364 |
} |
| 344 | 365 |
} |
| src/main/res/layout/meshfilecomponent.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="match_parent" |
|
| 4 |
android:layout_height="match_parent" |
|
| 5 |
android:orientation="horizontal"> |
|
| 6 |
|
|
| 7 |
<TextView |
|
| 8 |
android:id="@+id/meshfileComponentID" |
|
| 9 |
android:layout_width="wrap_content" |
|
| 10 |
android:layout_height="wrap_content" |
|
| 11 |
android:layout_marginEnd="5dp" |
|
| 12 |
android:layout_marginStart="5dp" |
|
| 13 |
android:layout_marginTop="5dp" |
|
| 14 |
android:layout_weight="1"/> |
|
| 15 |
|
|
| 16 |
<TextView |
|
| 17 |
android:id="@+id/meshfileComponentText" |
|
| 18 |
android:layout_width="wrap_content" |
|
| 19 |
android:layout_height="wrap_content" |
|
| 20 |
android:layout_marginEnd="5dp" |
|
| 21 |
android:layout_marginStart="5dp" |
|
| 22 |
android:layout_marginTop="5dp" |
|
| 23 |
android:layout_weight="1"/> |
|
| 24 |
|
|
| 25 |
<Button |
|
| 26 |
android:id="@+id/meshfileComponentDisappear" |
|
| 27 |
android:text="@string/disappear" |
|
| 28 |
android:layout_width="wrap_content" |
|
| 29 |
android:layout_height="wrap_content" |
|
| 30 |
android:layout_weight="0.2" |
|
| 31 |
android:layout_marginEnd="5dp" |
|
| 32 |
android:layout_marginStart="10dp" |
|
| 33 |
android:layout_marginTop="5dp"/> |
|
| 34 |
</LinearLayout> |
|
| src/main/res/layout/meshfilelayout.xml | ||
|---|---|---|
| 94 | 94 |
|
| 95 | 95 |
</LinearLayout> |
| 96 | 96 |
|
| 97 |
<View |
|
| 98 |
android:layout_height="4dip" |
|
| 99 |
android:background="#777777" |
|
| 100 |
android:layout_width="match_parent" |
|
| 101 |
/> |
|
| 102 |
|
|
| 103 |
<TextView |
|
| 104 |
android:text="@string/effComponents" |
|
| 105 |
android:layout_width="wrap_content" |
|
| 106 |
android:layout_height="wrap_content" |
|
| 107 |
android:gravity="center" |
|
| 108 |
android:layout_marginEnd="5dp" |
|
| 109 |
android:layout_marginStart="5dp" |
|
| 110 |
android:layout_marginTop="5dp"/> |
|
| 111 |
|
|
| 112 |
<View |
|
| 113 |
android:layout_height="4dip" |
|
| 114 |
android:background="#777777" |
|
| 115 |
android:layout_width="match_parent" |
|
| 116 |
/> |
|
| 117 |
|
|
| 118 |
<ScrollView |
|
| 119 |
android:id="@+id/meshfileScrollView" |
|
| 120 |
android:layout_width="match_parent" |
|
| 121 |
android:layout_height="0dp" |
|
| 122 |
android:layout_weight="0.5"> |
|
| 123 |
|
|
| 124 |
<LinearLayout |
|
| 125 |
android:id="@+id/meshfileComponentLayout" |
|
| 126 |
android:layout_width="match_parent" |
|
| 127 |
android:layout_height="wrap_content" |
|
| 128 |
android:orientation="vertical" > |
|
| 129 |
</LinearLayout> |
|
| 130 |
|
|
| 131 |
</ScrollView> |
|
| 132 |
|
|
| 97 | 133 |
</LinearLayout> |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 90 | 90 |
<string name="open">Open</string> |
| 91 | 91 |
<string name="vertices">Vert</string> |
| 92 | 92 |
<string name="time">Time</string> |
| 93 |
<string name="disappear">Disappear</string> |
|
| 94 |
<string name="appear">Appear</string> |
|
| 95 |
<string name="effComponents">Effect Components</string> |
|
| 93 | 96 |
|
| 94 | 97 |
<string name="quality0">Highest</string> |
| 95 | 98 |
<string name="quality1">High</string> |
Also available in: Unified diff
Progress with the MeshFile app.