diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/BoundingBoxVisitor.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/BoundingBoxVisitor.java index 0c5fa00..d8bbfd8 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/BoundingBoxVisitor.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/physics/BoundingBoxVisitor.java @@ -13,15 +13,15 @@ private ArrayList bsStack = new ArrayList(); // オブジェクトの階層毎のBoundingSphereのスタック private String partName = null; // 部品を指定する場合に使う private boolean inPart = false; - + public BoundingBoxVisitor() { partName = null; } - + public BoundingBoxVisitor(String partName) { this.partName = partName; } - + public void preVisit(Object3D obj) { pushTransform(obj); if (partName != null && obj.name.equals(partName)) { @@ -42,7 +42,7 @@ if (obj.bs == null) { obj.bs = obb.getBoundingSphere(); } - + obb = (OBB)obb.clone(); BoundingSphere bs = (BoundingSphere)obj.bs.clone(); for (int i = stackList.size() - 1; i >= 0; i--) { diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java index c4c535f..858def1 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java @@ -21,7 +21,9 @@ private ArrayList lights = null; private BackgroundBox skyBox = null; private Camera3D camera = null; - + private int width; + private int height; + public Viewer3D(Camera3D camera) { this.camera = camera; } @@ -35,15 +37,18 @@ @Override public void surfaceChanged(int width, int height) { + this.width =width; + this.height = height; gc3D.update(width, height, (float)camera.getFieldOfView(), (float)camera.getFrontClipDistance(), (float)camera.getBackClipDistance(), camera.isParallel()); } @Override public void onDrawFrame() { + gc3D.onDrawFrame(width, height); Position3D eye = camera.getViewPoint(); Position3D center = eye.clone().add(camera.getViewLine()); Vector3d up = camera.getViewUp(); - gc3D.update((float)camera.getFieldOfView(), (float)camera.getFrontClipDistance(), (float)camera.getBackClipDistance(), eye, center, up, camera.isParallel()); + gc3D.update(width, height, (float)camera.getFieldOfView(), (float)camera.getFrontClipDistance(), (float)camera.getBackClipDistance(), eye, center, up, camera.isParallel()); } @Override diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Appearance.java b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Appearance.java index 52cfcf1..648c647 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Appearance.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Appearance.java @@ -6,6 +6,8 @@ private TextureAttributes textureAttribute = null; private TexCoordGeneration texCoordGeneration = null; private TextureUnitState[] stateArray; + private TransparencyAttributes transparencyAttributes = null; + private ColoringAttributes coloringAttributes = null; public void setMaterial(Material m) { this.material = m; @@ -57,6 +59,22 @@ this.texCoordGeneration = texCoordGeneration; } + public TransparencyAttributes getTransparencyAttributes() { + return transparencyAttributes; + } + + public void setTransparencyAttributes(TransparencyAttributes transparencyAttributes) { + this.transparencyAttributes = transparencyAttributes; + } + + public ColoringAttributes getColoringAttributes() { + return coloringAttributes; + } + + public void setColoringAttributes(ColoringAttributes coloringAttributes) { + this.coloringAttributes = coloringAttributes; + } + @Override public NodeComponent cloneNodeComponent() { Appearance ap = new Appearance(); diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/ColoringAttributes.java b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/ColoringAttributes.java new file mode 100644 index 0000000..7a83098 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/ColoringAttributes.java @@ -0,0 +1,51 @@ +package org.ntlab.radishforandroidstudio.java3d; + +public class ColoringAttributes extends NodeComponent { + public static final int FASTEST = 0; + + public static final int NICEST = 1; + + public static final int SHADE_FLAT = 2; + + public static final int SHADE_GOURAUD = 3; + + private Color3f color; + + private int shadeModel; + + public ColoringAttributes() { + color = new Color3f(1.0f, 1.0f, 1.0f); + shadeModel = SHADE_GOURAUD; + } + + public ColoringAttributes(Color3f color, int shadeModel) { + this.color = color; + this.shadeModel = shadeModel; + } + + public ColoringAttributes(float r, float g, float b, int shadeModel) { + this.color = new Color3f(r, g, b); + this.shadeModel = shadeModel; + } + + public Color3f getColor() { + return color; + } + + public void setColor(Color3f color) { + this.color = color; + } + + public int getShadeModel() { + return shadeModel; + } + + public void setShadeModel(int shadeModel) { + this.shadeModel = shadeModel; + } + + @Override + public NodeComponent cloneNodeComponent() { + return new ColoringAttributes(color.clone(), shadeModel); + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java index cb0fe2e..893ecf6 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java @@ -1,8 +1,10 @@ package org.ntlab.radishforandroidstudio.java3d; +import android.opengl.GLES20; import android.opengl.GLU; import android.opengl.GLUtils; + import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import java.nio.FloatBuffer; @@ -18,7 +20,7 @@ private float aspect; private HashMap textureRegistry = new HashMap(); private HashMap lightRegistry = new HashMap(); - + public GraphicsContext3D(GL10 gl) { init(gl); } @@ -29,12 +31,12 @@ } return this; } - + public void fixAspect(float aspect) { this.bFixAspect = true; this.aspect = aspect; } - + public void init(GL10 gl) { this.gl = gl; // デプスバッファのテスト機能を有効にする @@ -42,24 +44,23 @@ // 陰面消去の動作を設定 gl.glDepthFunc(GL10.GL_LEQUAL); gl.glDepthMask(true); - - // ライトを有効にする - gl.glEnable(GL10.GL_LIGHTING); + // どの光源を使用するか指定 gl.glEnable(GL10.GL_LIGHT0); - + gl.glClearColor(0.0f,0.0f,0.0f,0.0f); - gl.glClearDepthf(1.0f); + gl.glClearDepthf(1.0f); } - + public void update(int width, int height, float fovx, float zNear, float zFar,boolean fParallel) { setGL10(gl); if (!bFixAspect) { aspect = (float)width / (float)height; } // ビューポートの設定 - gl.glViewport(0, 0, width, height); - +// gl.glViewport(0, 0, width, height); + GLES20.glViewport(0, 0, width, height); + // カメラの設定 gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 gl.glLoadIdentity(); // 座標の初期化 @@ -72,48 +73,63 @@ zNear, //ニアクリップ zFar);//ファークリップ }else{ - float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); - float bottom = -top; - float left = bottom * aspect; - float right = top * aspect; - gl.glOrthof(left, right, bottom, top, zNear, zFar); + float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); + float bottom = -top; + float left = bottom * aspect; + float right = top * aspect; + gl.glOrthof(left, right, bottom, top, zNear, zFar); } } - public void update(float fovx, float zNear, float zFar, Position3D eye, Position3D center, Vector3d up, boolean fParallel) { + public void onDrawFrame(int width, int height) { // 表示画面とデプスバッファのクリア gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); - + + // ビューポートの設定 + GLES20.glViewport(0, 0, width, height); + + // カメラの設定 + gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 + gl.glLoadIdentity(); // 座標の初期化 + + // モデルビュー行列の指定 + gl.glMatrixMode(GL10.GL_MODELVIEW); + gl.glLoadIdentity(); // 座標の初期化 + } + + public void update(int width, int height, float fovx, float zNear, float zFar, Position3D eye, Position3D center, Vector3d up, boolean fParallel) { + aspect = (float)width / (float)height; + // カメラの設定 gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 gl.glLoadIdentity(); // 座標の初期化 // 画角の設定 float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); if (!fParallel) { - GLU.gluPerspective(gl, - fovy, //Y方向の画角 - aspect, //アスペクト比 - zNear, //ニアクリップ - zFar);//ファークリップ + GLU.gluPerspective(gl, + fovy, //Y方向の画角 + aspect, //アスペクト比 + zNear, //ニアクリップ + zFar);//ファークリップ } else { - float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); - float bottom = -top; - float left = bottom * aspect; - float right = top * aspect; - gl.glOrthof(left, right, bottom, top, zNear, zFar); + float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); + float bottom = -top; + float left = bottom * aspect; + float right = top * aspect; + gl.glOrthof(left, right, bottom, top, zNear, zFar); } // モデルビュー行列の指定 gl.glMatrixMode(GL10.GL_MODELVIEW); // 座標の初期化 gl.glLoadIdentity(); - + // カメラ外部パラメータの設定 - GLU.gluLookAt(gl, - (float)eye.getX(), (float)eye.getY(), (float)eye.getZ(), - (float)center.getX(), (float)center.getY(), (float)center.getZ(), - (float)up.getX(), (float)up.getY(), (float)up.getZ()); + GLU.gluLookAt(gl, + (float)eye.getX(), (float)eye.getY(), (float)eye.getZ(), + (float)center.getX(), (float)center.getY(), (float)center.getZ(), + (float)up.getX(), (float)up.getY(), (float)up.getZ()); } - + public void setLight(Light l, int i) { lightRegistry.put(l, i); Color3f c = l.getColor(); @@ -129,7 +145,7 @@ gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_SPECULAR, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); } } - + public void updateLightState(Light l) { Integer i = lightRegistry.get(l); if (i == null) { @@ -160,17 +176,55 @@ float m[] = transform.getMatrix(); gl.glMultMatrixf(m, 0); } - + public void setAppearance(Appearance appearance) { this.appearance = appearance; + TransparencyAttributes transparencyAttributes = appearance.getTransparencyAttributes(); Material material = appearance.getMaterial(); - if (material != null) { + if (material != null && material.getLightingEnable()) { + // ライトを有効にする + gl.glEnable(GL10.GL_LIGHTING); // 表面属性の設定 - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_DIFFUSE, material.diffuse, 0); - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT, material.ambient, 0); - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_SPECULAR, material.specular, 0); - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_EMISSION, material.emissive, 0); - gl.glMaterialf(GL10.GL_FRONT, GL10.GL_SHININESS, material.shininess); + if (transparencyAttributes == null) { + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_DIFFUSE, material.diffuse, 0); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT, material.ambient, 0); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_SPECULAR, material.specular, 0); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_EMISSION, material.emissive, 0); + gl.glMaterialf(GL10.GL_FRONT, GL10.GL_SHININESS, material.shininess); + } else { + float diffuse[] = material.diffuse.clone(); + float ambient[] = material.ambient.clone(); + float specular[] = material.specular.clone(); + float emissive[] = material.emissive.clone(); + diffuse[3] = transparencyAttributes.getTransparency(); + ambient[3] = transparencyAttributes.getTransparency(); + specular[3] = transparencyAttributes.getTransparency(); + emissive[3] = transparencyAttributes.getTransparency(); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_DIFFUSE, diffuse, 0); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT, ambient, 0); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_SPECULAR, specular, 0); + gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_EMISSION, emissive, 0); + gl.glMaterialf(GL10.GL_FRONT, GL10.GL_SHININESS, material.shininess); + } + } else { + // ライトを無効にする + gl.glDisable(GL10.GL_LIGHTING); + Color3f color; + if (appearance.getColoringAttributes() != null) { + color = appearance.getColoringAttributes().getColor(); + } else { + color = new Color3f(1.0f, 1.0f, 1.0f); + } + if (transparencyAttributes == null) { + gl.glColor4f(color.r, color.g, color.b, 1.0f); + } else { + gl.glColor4f(color.r, color.g, color.b, transparencyAttributes.getTransparency()); + } + } + if (transparencyAttributes != null) { + // 透過属性が指定されている場合 + gl.glDepthMask(false); + setTransparencyAttributes(transparencyAttributes); } if (appearance.getTextureUnitCount() == 0) { // テクスチャユニットを使っていない場合(通常のテクスチャの場合) @@ -199,22 +253,51 @@ } else { // 通常の場合 gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[0]); - ImageComponent[] imageComponents = tex.getImages(); + ImageComponent[] imageComponents = tex.getImages(); for (int level = 0; level < imageComponents.length; level++) { GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, ((ImageComponent2D)imageComponents[level]).getBitmap(), 0); // ((ImageComponent2D)imageComponents[i]).getBitmap().recycle(); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST); } } textureRegistry.put(tex, textureId[0]); } } - + + public void resetAppearance(Appearance appearance) { + if (appearance.getTextureUnitCount() == 0) { + // テクスチャユニットを使っていない場合(通常のテクスチャの場合) + if (appearance.getTexture() != null) { + gl.glDisable(GL10.GL_TEXTURE_2D); + } + } else { + // テクスチャユニットを使っている場合 + for (int n = 0; n < appearance.getTextureUnitCount(); n++) { + gl.glActiveTexture(GL10.GL_TEXTURE0 + n); + gl.glDisable(GL10.GL_TEXTURE_2D); + } + gl.glActiveTexture(GL10.GL_TEXTURE0); + } + if (appearance.getTransparencyAttributes() != null) { + // 透明属性を使っている場合 + gl.glDisable(GL10.GL_BLEND); + gl.glDepthMask(true); + } + Material material = appearance.getMaterial(); + if (material != null) { + if (material.getLightingEnable()) { + // ライトを有効にする + gl.glDisable(GL10.GL_LIGHTING); + } + } + } + public void draw(Shape3D node) { if (node == null) return; - setAppearance(node.getAppearance()); + setAppearance(node.getAppearance()); draw(node.getGeometry()); + resetAppearance(node.getAppearance()); } public void draw(Geometry g) { @@ -240,7 +323,7 @@ TextureAttributes ta = tus.getTextureAttributes(); if (ta != null) setTextureAttributes(ta); } - } + } } if (g instanceof GeometryArray) { // バッファの設定 @@ -265,7 +348,7 @@ FloatBuffer uvBuffer = ((GeometryArray)g).getUVBuffer(); gl.glTexCoordPointer(4, GL10.GL_FLOAT, 0, uvBuffer); } - + // ジオメトリの描画 if (g instanceof TriangleArray) { TriangleArray ta = (TriangleArray)g; @@ -320,7 +403,7 @@ start += vertexCount; } } - + if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_2) != 0) { gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); } else if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_3) != 0) { @@ -333,39 +416,58 @@ } gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); } - if (appearance.getTextureUnitCount() == 0) { - // テクスチャユニットを使っていない場合(通常のテクスチャの場合) - if (appearance.getTexture() != null) { - gl.glDisable(GL10.GL_TEXTURE_2D); - } - } else { - // テクスチャユニットを使っている場合 - for (int n = 0; n < appearance.getTextureUnitCount(); n++) { - gl.glActiveTexture(GL10.GL_TEXTURE0 + n); - gl.glDisable(GL10.GL_TEXTURE_2D); - } - gl.glActiveTexture(GL10.GL_TEXTURE0); + } + + private void setTransparencyAttributes(TransparencyAttributes ta) { + int transparencyMode = ta.getTransparencyMode(); + switch (transparencyMode) { + case TransparencyAttributes.FASTEST: + case TransparencyAttributes.NICEST: + case TransparencyAttributes.BLENDED: + gl.glEnable(GL10.GL_BLEND); + gl.glBlendFunc(getBlendFunction(ta.getSrcBlendFunction()), getBlendFunction(ta.getDstBlendFunction())); + break; } } + private int getBlendFunction(int blendFunction) { + switch (blendFunction) { + case TransparencyAttributes.BLEND_SRC_ALPHA: + return GL10.GL_SRC_ALPHA; + case TransparencyAttributes.BLEND_SRC_COLOR: + return GL10.GL_SRC_COLOR; + case TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA: + return GL10.GL_ONE_MINUS_SRC_ALPHA; + case TransparencyAttributes.BLEND_ONE_MINUS_SRC_COLOR: + return GL10.GL_ONE_MINUS_SRC_COLOR; + case TransparencyAttributes.BLEND_ONE_MINUS_DST_COLOR: + return GL10.GL_ONE_MINUS_DST_COLOR; + case TransparencyAttributes.BLEND_ONE: + return GL10.GL_ONE; + case TransparencyAttributes.BLEND_ZERO: + return GL10.GL_ZERO; + } + return GL10.GL_ZERO; + } + private void setTextureAttributes(TextureAttributes ta) { int textureMode = ta.getTextureMode(); switch (textureMode) { - case TextureAttributes.REPLACE: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE); - break; - case TextureAttributes.BLEND: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_BLEND); - break; + case TextureAttributes.REPLACE: + gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE); + break; + case TextureAttributes.BLEND: + gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_BLEND); + break; // case TextureAttributes.COMBINE: // gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_COMBINE); // break; - case TextureAttributes.MODULATE: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE); - break; - case TextureAttributes.DECAL: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL); - break; + case TextureAttributes.MODULATE: + gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE); + break; + case TextureAttributes.DECAL: + gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL); + break; } // int perspCorrectionMode = ta.getPerspectiveCorrectionMode(); // switch (perspCorrectionMode) { diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Material.java b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Material.java index f8e9247..01e5da3 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Material.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/Material.java @@ -1,25 +1,15 @@ package org.ntlab.radishforandroidstudio.java3d; public class Material extends NodeComponent { - float diffuseR = 1.0f; - float diffuseG = 1.0f; - float diffuseB = 1.0f; - float ambientR = 0.2f; - float ambientG = 0.2f; - float ambientB = 0.2f; - float specularR = 1.0f; - float specularG = 1.0f; - float specularB = 1.0f; - float emissiveR = 0.0f; - float emissiveG = 0.0f; - float emissiveB = 0.0f; - float shininess = 64.0f; + float shininess = 64.0f; float[] diffuse = null; float[] ambient = null; float[] specular = null; float[] emissive = null; + boolean lightingEnable = true; public Material() { + lightingEnable = true; setDiffuseColor(1.0f, 1.0f, 1.0f); setAmbientColor(0.2f, 0.2f, 0.2f); setSpecularColor(1.0f, 1.0f, 1.0f); @@ -28,30 +18,18 @@ } public void setDiffuseColor(float r, float g, float b) { - this.diffuseR = r; - this.diffuseG = g; - this.diffuseB = b; diffuse = new float[]{r, g ,b, 1.0f}; } public void setAmbientColor(float r, float g, float b) { - this.ambientR = r; - this.ambientG = g; - this.ambientB = b; ambient = new float[]{r, g ,b, 1.0f}; } public void setSpecularColor(float r, float g, float b) { - this.specularR = r; - this.specularG = g; - this.specularB = b; specular = new float[]{r, g ,b, 1.0f}; } public void setEmissiveColor(float r, float g, float b) { - this.emissiveR = r; - this.emissiveG = g; - this.emissiveB = b; emissive = new float[]{r, g ,b, 1.0f}; } @@ -59,14 +37,23 @@ this.shininess = shininess; } + public boolean getLightingEnable() { + return lightingEnable; + } + + public void setLightingEnable(boolean lightingEnable) { + this.lightingEnable = lightingEnable; + } + @Override public NodeComponent cloneNodeComponent() { Material m = new Material(); - m.setDiffuseColor(diffuseR, diffuseG, diffuseB); - m.setAmbientColor(ambientR, ambientG, ambientB); - m.setSpecularColor(specularR, specularG, specularB); - m.setEmissiveColor(emissiveR, emissiveG, emissiveB); + m.setDiffuseColor(diffuse[0], diffuse[1], diffuse[2]); + m.setAmbientColor(ambient[0], ambient[1], ambient[2]); + m.setSpecularColor(specular[0], specular[1], specular[2]); + m.setEmissiveColor(emissive[0], emissive[1], emissive[2]); m.setShininess(shininess); + m.setLightingEnable(lightingEnable); return m; } diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/TransparencyAttributes.java b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/TransparencyAttributes.java new file mode 100644 index 0000000..4df5318 --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/java3d/TransparencyAttributes.java @@ -0,0 +1,93 @@ +package org.ntlab.radishforandroidstudio.java3d; + +public class TransparencyAttributes extends NodeComponent { + public static final int FASTEST = 0; + + public static final int NICEST = 1; + + public static final int BLENDED = 2; + + public static final int SCREEN_DOOR = 3; + + public static final int NONE = 4; + + public static final int BLEND_ZERO = 0; + + public static final int BLEND_ONE = 1; + + public static final int BLEND_SRC_ALPHA = 2; + + public static final int BLEND_ONE_MINUS_SRC_ALPHA = 3; + + public static final int BLEND_DST_COLOR = 4; + + public static final int BLEND_ONE_MINUS_DST_COLOR = 5; + + public static final int BLEND_SRC_COLOR = 6; + + public static final int BLEND_ONE_MINUS_SRC_COLOR = 7; + + static final int BLEND_CONSTANT_COLOR = 8; + + static final int MAX_BLEND_FUNC_TABLE_SIZE = 9; + + private int transparencyMode = NONE; + + private float transparency = 0.0f; + + private int srcBlendFunction = BLEND_SRC_ALPHA; + + private int dstBlendFunction = BLEND_ONE_MINUS_SRC_ALPHA; + + public TransparencyAttributes() { + this(NONE, 0.0f); + } + + public TransparencyAttributes(int tMode, float tVal) { + this(tMode, tVal, BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); + } + + public TransparencyAttributes(int tMode, float tVal, int srcBlendFunction, int dstBlendFunction) { + transparencyMode = tMode; + transparency = tVal; + this.srcBlendFunction = srcBlendFunction; + this.dstBlendFunction = dstBlendFunction; + } + + public int getTransparencyMode() { + return transparencyMode; + } + + public void setTransparencyMode(int transparencyMode) { + this.transparencyMode = transparencyMode; + } + + public float getTransparency() { + return transparency; + } + + public void setTransparency(float transparency) { + this.transparency = transparency; + } + + public int getSrcBlendFunction() { + return srcBlendFunction; + } + + public void setSrcBlendFunction(int srcBlendFunction) { + this.srcBlendFunction = srcBlendFunction; + } + + public int getDstBlendFunction() { + return dstBlendFunction; + } + + public void setDstBlendFunction(int dstBlendFunction) { + this.dstBlendFunction = dstBlendFunction; + } + + @Override + public NodeComponent cloneNodeComponent() { + return new TransparencyAttributes(transparencyMode, transparency, srcBlendFunction, dstBlendFunction); + } +} diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/test/TestDiceActivity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/test/TestDiceActivity.java index 5378914..7d5b9fd 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/test/TestDiceActivity.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/test/TestDiceActivity.java @@ -41,6 +41,7 @@ // サイコロの作成 Appearance ap1 = new Appearance(); + ap1.setMaterial(new Material()); TextureCubeMap tex1 = new TextureCubeMap(TextureCubeMap.BASE_LEVEL, TextureCubeMap.RGB, 0); TextureLoader loader = new TextureLoader(getResources(), R.drawable.dice_1, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); tex1.setImage(0, TextureCubeMap.POSITIVE_Z, loader.getImage());