得物.apk(点击下载) / ModelView.java


package com.du.animatiom3d.engine;

import a.f;
import a40.j;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.opengl.EGL14;
import android.opengl.EGLContext;
import android.opengl.GLES30;
import android.opengl.GLSurfaceView;
import android.opengl.GLUtils;
import android.view.GestureDetector;
import android.view.MotionEvent;
import androidx.core.view.MotionEventCompat;
import com.du.animatiom3d.controller.IAnimationListener;
import com.du.animatiom3d.data.ModelData;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.shizhuang.duapp.libs.duimageloaderview.options.DuRequestOptions;
import gg0.n;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import o5.i;
import q4.k;
import r4.a;

@SuppressLint({"NewApi"})
public class ModelView extends GLSurfaceView {
    public static final /* synthetic */ int T = 0;
    public q4.a A;
    public r4.a B;
    public ByteBuffer C;
    public IReadPixelLister D;
    public IModelCreateLister E;
    public boolean F = false;
    public boolean G = false;
    public float H = i.f36333a;
    public boolean I = false;
    public ExecutorService J;
    public boolean K = false;
    public ModelData L;
    public IAnimationListener M;
    public dg1.a N;
    public volatile boolean O;
    public boolean P;
    public int Q;
    public boolean R = false;
    public Bitmap S = null;
    public GestureDetector b;

    /* renamed from: c  reason: collision with root package name */
    public a f4326c;
    public ValueAnimator d;
    public ValueAnimator e;
    public ValueAnimator f;

    /* renamed from: g  reason: collision with root package name */
    public ValueAnimator f4327g;

    /* renamed from: h  reason: collision with root package name */
    public ValueAnimator f4328h;
    public ValueAnimator i;
    public ValueAnimator j;
    public boolean k;
    public float l;
    public float m;
    public float n;
    public float o;
    public float p;

    /* renamed from: q  reason: collision with root package name */
    public Context f4329q;
    public float r = 0.38f;
    public float s = 2.38f;
    public Timer t;

    /* renamed from: u  reason: collision with root package name */
    public TimerTask f4330u;

    /* renamed from: v  reason: collision with root package name */
    public int f4331v = 0;
    public int w = 31;
    public float x = i.f36333a;
    public float y = i.f36333a;
    public float z = i.f36333a;

    public interface IModelCreateLister {
        void modelCreated();
    }

    public interface IReadPixelLister {
        void getPixelCompelete(Bitmap bitmap);

        void getVideoComplete(String str);
    }

    public class a {

        /* renamed from: a  reason: collision with root package name */
        public float f4332a;

        public a(h.a aVar) {
        }

        public final float a(MotionEvent motionEvent) {
            return (float) j.a((double) (motionEvent.getY(0) - motionEvent.getY(1)), 2.0d, Math.pow((double) (motionEvent.getX(0) - motionEvent.getX(1)), 2.0d));
        }

        public void onTouchEvent(MotionEvent motionEvent) {
            int action = motionEvent.getAction() & MotionEventCompat.ACTION_MASK;
            if (action == 2) {
                float a5 = a(motionEvent);
                ModelView modelView = ModelView.this;
                float f = (((a5 / this.f4332a) - 1.0f) * 0.3f) + modelView.o;
                modelView.o = f;
                if (f >= 1.0f) {
                    modelView.o = 1.0f;
                }
                float f12 = modelView.o;
                float f13 = modelView.r;
                if (f12 <= f13) {
                    modelView.o = f13;
                }
                this.f4332a = a5;
            } else if (action == 5) {
                this.f4332a = a(motionEvent);
            }
        }
    }

    @SuppressLint({"NewApi"})
    public class b implements GLSurfaceView.Renderer {
        public int b;

        /* renamed from: c  reason: collision with root package name */
        public int f4333c;
        public int[] d = new int[4];
        public int[] e = new int[4];
        public int[] f = new int[4];

        /* renamed from: g  reason: collision with root package name */
        public int f4334g = -1;

        /* renamed from: h  reason: collision with root package name */
        public q4.b f4335h;
        public long i;

        public b(fu.a aVar) {
        }

        public void onDrawFrame(GL10 gl10) {
            GLES30.glClear(16640);
            GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
            s4.c.i(i.f36333a, i.f36333a, ModelView.this.x, i.f36333a, i.f36333a, i.f36333a, i.f36333a, 1.0f, i.f36333a);
            ModelView.this.c();
            ModelView modelView = ModelView.this;
            float f12 = modelView.y;
            float f13 = modelView.z;
            float[] fArr = s4.c.f37997a;
            fArr[0] = 0.0f;
            fArr[1] = f12;
            fArr[2] = f13;
            ByteBuffer allocateDirect = ByteBuffer.allocateDirect(12);
            allocateDirect.order(ByteOrder.nativeOrder());
            FloatBuffer asFloatBuffer = allocateDirect.asFloatBuffer();
            s4.c.d = asFloatBuffer;
            asFloatBuffer.put(fArr);
            s4.c.d.position(0);
            s4.c.f();
            s4.c.l(i.f36333a, ModelView.this.p, i.f36333a);
            ModelView modelView2 = ModelView.this;
            float f14 = modelView2.o;
            int i3 = ModelView.T;
            float f15 = modelView2.B.s.d;
            if (f15 > i.f36333a) {
                f14 *= f15;
            }
            s4.c.h(f14, f14, f14);
            s4.c.g(-ModelView.this.l, 1.0f, i.f36333a, i.f36333a);
            s4.c.g(-ModelView.this.m, i.f36333a, 1.0f, i.f36333a);
            s4.c.g(-ModelView.this.n, i.f36333a, i.f36333a, 1.0f);
            a.C0634a aVar = ModelView.this.B.s;
            s4.c.l(i.f36333a - aVar.f37630a, i.f36333a - aVar.b, i.f36333a - aVar.f37631c);
            GLES30.glBindFramebuffer(36160, this.d[0]);
            GLES30.glViewport(0, 0, this.b, this.f4333c);
            GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
            GLES30.glClear(16640);
            r4.a aVar2 = ModelView.this.B;
            float[] a5 = s4.c.a();
            float[] d12 = s4.c.d();
            GLES30.glUseProgram(aVar2.f37626c);
            GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(aVar2.f37626c, "uMMatrix"), 1, false, a5, 0);
            GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(aVar2.f37626c, "uMProjCameraMatrix"), 1, false, d12, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar2.f37626c, "uLightLocation"), 1, s4.c.f37998c);
            int i12 = aVar2.i;
            if (i12 != 0) {
                GLES30.glBindVertexArray(i12);
                GLES30.glDrawElements(4, aVar2.f37628h, 5125, 0);
                GLES30.glBindVertexArray(0);
            }
            GLES30.glFlush();
            GLES30.glBindFramebuffer(36160, this.d[1]);
            GLES30.glViewport(0, 0, this.b, this.f4333c);
            GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
            GLES30.glClear(16640);
            r4.a aVar3 = ModelView.this.B;
            float[] b2 = s4.c.b();
            float[] c5 = s4.c.c();
            float[] a12 = s4.c.a();
            GLES30.glUseProgram(aVar3.b);
            int i13 = aVar3.d;
            if (i13 > 0) {
                s4.b.a(i13, 3);
                GLES30.glUniform1i(GLES30.glGetUniformLocation(aVar3.b, "albedoMap"), 3);
            }
            int i14 = aVar3.f;
            if (i14 > 0) {
                s4.b.a(i14, 6);
                GLES30.glUniform1i(GLES30.glGetUniformLocation(aVar3.b, "roughnessMap"), 6);
                GLES30.glUniform1f(GLES30.glGetUniformLocation(aVar3.b, "isShowRoughness"), 1.0f);
            }
            int i15 = aVar3.e;
            if (i15 > 0) {
                s4.b.a(i15, 5);
                GLES30.glUniform1i(GLES30.glGetUniformLocation(aVar3.b, "metallicMap"), 5);
                GLES30.glUniform1f(GLES30.glGetUniformLocation(aVar3.b, "isShowMetallic"), 1.0f);
            }
            int i16 = aVar3.f37627g;
            if (i16 > 0) {
                s4.b.a(i16, 4);
                GLES30.glUniform1i(GLES30.glGetUniformLocation(aVar3.b, "normalMap"), 4);
                GLES30.glUniform1f(GLES30.glGetUniformLocation(aVar3.b, "isShowNormal"), 1.0f);
            }
            GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(aVar3.b, "projection"), 1, false, b2, 0);
            GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(aVar3.b, "view"), 1, false, c5, 0);
            GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(aVar3.b, "model"), 1, false, a12, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "camPos"), 1, aVar3.j, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "pointLightPositions[0]"), 1, aVar3.k, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "pointLightColors[0]"), 1, aVar3.n, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "pointLightPositions[1]"), 1, aVar3.l, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "pointLightColors[1]"), 1, aVar3.o, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "pointLightPositions[2]"), 1, aVar3.m, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "pointLightColors[2]"), 1, aVar3.p, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "directionLightDir"), 1, aVar3.f37629q, 0);
            GLES30.glUniform3fv(GLES30.glGetUniformLocation(aVar3.b, "directionLightColor"), 1, aVar3.r, 0);
            int i17 = aVar3.i;
            if (i17 != 0) {
                GLES30.glBindVertexArray(i17);
                GLES30.glDrawElements(4, aVar3.f37628h, 5125, 0);
                GLES30.glBindVertexArray(0);
            }
            GLES30.glFlush();
            if (ModelView.this.O) {
                ModelView modelView3 = ModelView.this;
                int i18 = modelView3.Q;
                if (i18 == 0) {
                    if (modelView3.N == null) {
                        try {
                            modelView3.N = new dg1.a();
                            File c12 = s4.a.c(ModelView.this.f4329q);
                            if (c12 != null) {
                                c12.getAbsolutePath();
                                dg1.a aVar4 = ModelView.this.N;
                                EGLContext eglGetCurrentContext = EGL14.eglGetCurrentContext();
                                ModelView modelView4 = ModelView.this;
                                aVar4.prepare(720, 1280, eglGetCurrentContext, modelView4.f4329q, c12, modelView4.P, new b(this));
                                ModelView.this.N.setExcludeAudio(true);
                                ModelView.this.N.startVideoCapture();
                            }
                        } catch (IOException e6) {
                            e6.printStackTrace();
                        }
                    }
                    ModelView.this.Q = 1;
                } else if (i18 != 1) {
                    StringBuilder h12 = f.h("unknown status ");
                    h12.append(ModelView.this.Q);
                    throw new RuntimeException(h12.toString());
                }
            } else {
                ModelView modelView5 = ModelView.this;
                int i19 = modelView5.Q;
                if (i19 != 0) {
                    if (i19 == 1) {
                        if (modelView5.R) {
                            dg1.a aVar5 = modelView5.N;
                            if (aVar5 != null) {
                                aVar5.cancelVideoCapture();
                                ModelView.this.N.release();
                                ModelView.this.N = null;
                            }
                        } else {
                            dg1.a aVar6 = modelView5.N;
                            if (aVar6 != null) {
                                aVar6.stopVideoCapture();
                                ModelView.this.N.release();
                                ModelView.this.N = null;
                            }
                        }
                        ModelView.this.Q = 0;
                    } else {
                        StringBuilder h13 = f.h("unknown status ");
                        h13.append(ModelView.this.Q);
                        throw new RuntimeException(h13.toString());
                    }
                }
            }
            if (this.f4334g == -1) {
                this.f4334g = ModelView.this.a();
            }
            long currentTimeMillis = System.currentTimeMillis();
            if (this.f4334g != -1 && ModelView.this.O && currentTimeMillis - this.i >= 42) {
                this.i = currentTimeMillis;
                GLES30.glBindFramebuffer(36160, this.d[3]);
                GLES30.glViewport(0, 0, this.b, this.f4333c);
                GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
                GLES30.glClear(16640);
                q4.b bVar = this.f4335h;
                int i22 = this.f4334g;
                GLES30.glUseProgram(bVar.e);
                GLES30.glBindVertexArray(bVar.k);
                GLES30.glActiveTexture(33984);
                GLES30.glBindTexture(3553, i22);
                GLES30.glUniform1i(bVar.f37240h, 0);
                GLES30.glDrawArrays(5, 0, 4);
                GLES30.glBindTexture(3553, 0);
                GLES30.glBindVertexArray(0);
                GLES30.glUseProgram(0);
                GLES30.glFlush();
                GLES30.glDisable(2929);
                GLES30.glBindFramebuffer(36160, this.d[2]);
                GLES30.glViewport(0, 0, this.b, this.f4333c);
                GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
                GLES30.glClear(16384);
                q4.a aVar7 = ModelView.this.A;
                int[] iArr = this.f;
                aVar7.a(iArr[3], iArr[1]);
                GLES30.glFlush();
                dg1.a aVar8 = ModelView.this.N;
                if (aVar8 != null) {
                    aVar8.b(this.f[2]);
                    ModelView.this.N.a();
                }
            }
            GLES30.glEnable(2929);
            GLES30.glBindFramebuffer(36160, 0);
            GLES30.glViewport(0, 0, this.b, this.f4333c);
            GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
            GLES30.glClear(16640);
            q4.a aVar9 = ModelView.this.A;
            int[] iArr2 = this.f;
            aVar9.a(iArr2[0], iArr2[1]);
            GLES30.glFlush();
            ModelView modelView6 = ModelView.this;
            if (modelView6.I) {
                modelView6.I = false;
                if (modelView6.C == null) {
                    modelView6.C = ByteBuffer.allocateDirect(this.b * this.f4333c * 4).order(ByteOrder.nativeOrder());
                }
                if (ModelView.this.getContext() != null) {
                    ModelView modelView7 = ModelView.this;
                    if (modelView7.k) {
                        modelView7.C.clear();
                        GLES30.glReadPixels(0, 0, this.b, this.f4333c, 6408, 5121, ModelView.this.C);
                        ModelView.this.C.rewind();
                        ModelView modelView8 = ModelView.this;
                        ByteBuffer byteBuffer = modelView8.C;
                        int i23 = this.b;
                        int i24 = this.f4333c;
                        if (byteBuffer != null && byteBuffer.capacity() == i23 * i24 * 4) {
                            if (modelView8.J == null) {
                                modelView8.J = p4.c.g("​com.du.animatiom3d.engine.ModelView");
                            }
                            modelView8.J.execute(new q4.j(modelView8, i23, i24, byteBuffer, 0));
                        }
                    }
                }
            }
            s4.c.e();
            GLES30.glBindFramebuffer(36160, 0);
            GLES30.glBindTexture(3553, 0);
            GLES30.glFinish();
        }

        public void onSurfaceChanged(GL10 gl10, int i3, int i12) {
            this.b = i3;
            this.f4333c = i12;
            GLES30.glViewport(0, 0, i3, i12);
            float f12 = ((float) i3) / ((float) i12);
            s4.c.k(-f12, f12, -1.0f, 1.0f, 2.0f, 100.0f);
            ModelView modelView = ModelView.this;
            modelView.x = 8.0f;
            modelView.c();
            GLES30.glGenFramebuffers(4, this.d, 0);
            GLES30.glGenRenderbuffers(4, this.e, 0);
            GLES30.glGenTextures(4, this.f, 0);
            for (int i13 = 0; i13 < 4; i13++) {
                GLES30.glBindFramebuffer(36160, this.d[i13]);
                GLES30.glBindRenderbuffer(36161, this.e[i13]);
                GLES30.glRenderbufferStorage(36161, 33189, this.b, this.f4333c);
                GLES30.glBindTexture(3553, this.f[i13]);
                GLES30.glTexParameterf(3553, 10241, 9729.0f);
                GLES30.glTexParameterf(3553, 10240, 9729.0f);
                GLES30.glTexParameterf(3553, 10242, 33071.0f);
                GLES30.glTexParameterf(3553, 10243, 33071.0f);
                GLES30.glTexImage2D(3553, 0, 6408, this.b, this.f4333c, 0, 6408, 5121, null);
                GLES30.glFramebufferTexture2D(36160, 36064, 3553, this.f[i13], 0);
                GLES30.glFramebufferRenderbuffer(36160, 36096, 36161, this.e[i13]);
            }
        }

        public void onSurfaceCreated(GL10 gl10, EGLConfig eGLConfig) {
            GLES30.glClearColor(i.f36333a, i.f36333a, i.f36333a, i.f36333a);
            GLES30.glEnable(2929);
            GLES30.glDisable(2884);
            s4.c.j();
            ModelView modelView = ModelView.this;
            modelView.A = new q4.a(modelView);
            ModelView modelView2 = ModelView.this;
            modelView2.B = new r4.a(modelView2.f4329q, modelView2.L);
            this.f4335h = new q4.b();
            this.f4334g = ModelView.this.a();
            IModelCreateLister iModelCreateLister = ModelView.this.E;
            if (iModelCreateLister != null) {
                iModelCreateLister.modelCreated();
            }
        }
    }

    public class c implements GestureDetector.OnGestureListener {
        public c(n nVar) {
        }

        public boolean onDown(MotionEvent motionEvent) {
            return false;
        }

        public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f12) {
            float f13 = (f / 100000.0f) * 180.0f;
            float f14 = (f12 / 100000.0f) * 180.0f;
            ValueAnimator valueAnimator = ModelView.this.j;
            if (valueAnimator != null && valueAnimator.isRunning()) {
                ModelView.this.j.end();
                ModelView.this.j = null;
            }
            ModelView.this.j = ValueAnimator.ofFloat(1.0f, i.f36333a);
            ModelView.this.j.setDuration(1000L);
            g.a.s(ModelView.this.j);
            ModelView.this.j.addUpdateListener(new q4.n(this, f13, f14));
            ModelView.this.j.start();
            return false;
        }

        public void onLongPress(MotionEvent motionEvent) {
        }

        public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f12) {
            if (f <= 100.0f && f12 <= 100.0f) {
                ModelView modelView = ModelView.this;
                float f13 = modelView.m + (f * 0.33333334f);
                modelView.m = f13;
                modelView.m = f13 % 360.0f;
                float f14 = modelView.l + (f12 * 0.33333334f);
                modelView.l = f14;
                modelView.l = f14 % 360.0f;
            }
            return false;
        }

        public void onShowPress(MotionEvent motionEvent) {
        }

        public boolean onSingleTapUp(MotionEvent motionEvent) {
            return false;
        }
    }

    public ModelView(Context context, ModelData modelData, float f12, float f13) {
        super(context);
        this.f4329q = context;
        this.L = modelData;
        this.s = f12;
        this.r = f13;
        b();
        if (this.L == null || new File(this.L.getBaseCorlor()).exists()) {
            setEGLContextClientVersion(((ActivityManager) this.f4329q.getSystemService(PushConstants.INTENT_ACTIVITY_NAME)).getDeviceConfigurationInfo().reqGlEsVersion >= 196608 ? 3 : 2);
            setZOrderOnTop(true);
            setEGLConfigChooser(8, 8, 8, 8, 16, 0);
            getHolder().setFormat(1);
            setRenderer(new b(null));
            setRenderMode(1);
            this.b = new GestureDetector(getContext(), new c(null));
            this.f4326c = new a(null);
        }
    }

    public int a() {
        Bitmap bitmap = this.S;
        if (bitmap == null || bitmap.isRecycled()) {
            b();
            return -1;
        }
        int[] iArr = new int[1];
        GLES30.glGenTextures(1, iArr, 0);
        GLES30.glBindTexture(3553, iArr[0]);
        GLES30.glTexParameterf(3553, 10241, 9728.0f);
        GLES30.glTexParameterf(3553, 10240, 9729.0f);
        GLES30.glTexParameterf(3553, 10242, 10497.0f);
        GLES30.glTexParameterf(3553, 10243, 10497.0f);
        GLUtils.texImage2D(3553, 0, this.S, 0);
        this.S.recycle();
        return iArr[0];
    }

    public final void b() {
        ((DuRequestOptions) mn.a.a("https://apk.poizon.com/duApp/Android_Config/resource/mall/app/common/animation3d_bg_product_detail_3d.webp").F(this.f4329q.getApplicationContext()).u(new k(this, 0))).y();
    }

    public void c() {
        this.y = 0.15f - (this.p * 0.2f);
        this.z = 9.0f;
    }

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.k = true;
    }

    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.k = false;
        ExecutorService executorService = this.J;
        if (executorService != null && !executorService.isShutdown()) {
            this.J.shutdown();
            this.J = null;
        }
    }

    @SuppressLint({"ClickableViewAccessibility"})
    public boolean onTouchEvent(MotionEvent motionEvent) {
        ValueAnimator valueAnimator;
        if (!this.G) {
            return true;
        }
        if (motionEvent.getAction() == 2 && (valueAnimator = this.d) != null && valueAnimator.isRunning()) {
            this.d.cancel();
            IAnimationListener iAnimationListener = this.M;
            if (iAnimationListener != null) {
                iAnimationListener.onFirstClick();
            }
        }
        int pointerCount = motionEvent.getPointerCount();
        if (pointerCount == 1) {
            this.b.onTouchEvent(motionEvent);
        } else if (pointerCount == 2) {
            this.f4326c.onTouchEvent(motionEvent);
        }
        return true;
    }

    public void setCreateLister(IModelCreateLister iModelCreateLister) {
        this.E = iModelCreateLister;
    }

    public void setListener(IAnimationListener iAnimationListener) {
        this.M = iAnimationListener;
    }

    public void setUpOffset(float f12) {
        this.H = f12;
    }

    public void setiReadPixelLister(IReadPixelLister iReadPixelLister) {
        this.D = iReadPixelLister;
    }
}