package com.seewo.factoryaging.opengl3d;

import android.content.Context;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.util.Log;
import com.cvte.vman.instance.InvokeCmd;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

/* JADX INFO: compiled from: ModelRenderer.java */
/* JADX INFO: loaded from: classes.dex */
public class c implements GLSurfaceView.Renderer {
    private int a;
    private int b;
    private int c = 0;
    private com.seewo.factoryaging.opengl3d.h.f d;
    private final com.seewo.factoryaging.opengl3d.j.c e;
    private Map<com.seewo.factoryaging.opengl3d.j.c, com.seewo.factoryaging.opengl3d.j.c> f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private Map<Object, Integer> f327g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private Map<com.seewo.factoryaging.opengl3d.j.c, com.seewo.factoryaging.opengl3d.j.c> f328h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private Map<com.seewo.factoryaging.opengl3d.j.c, com.seewo.factoryaging.opengl3d.j.c> f329i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final float[] f330j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final float[] f331k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private final float[] f332l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private final float[] f333m;
    private final float[] n;
    private final float[] o;
    private final float[] p;
    private final float[] q;
    private final float[] r;
    private final float[] s;
    private final float[] t;
    private Map<com.seewo.factoryaging.opengl3d.j.c, Boolean> u;
    private com.seewo.factoryaging.opengl3d.h.c v;
    private boolean w;
    private com.seewo.factoryaging.opengl3d.i.c x;
    private static final String y = c.class.getName();
    private static float z = 0.64f;
    private static final float[] A = {1.0f, 1.0f, 1.0f, 0.5f};
    private static final float[] B = {0.0f, 0.0f, 0.0f, 0.5f};
    private static final float[] C = {1.0f, 0.0f, 0.0f, 0.5f};
    private static final float[] D = {0.0f, 1.0f, 0.0f, 0.5f};
    private static final float[] E = {0.0f, 0.0f, 1.0f, 0.5f};

    public c(Context context, com.seewo.factoryaging.opengl3d.i.c cVar) throws IllegalAccessException, IOException {
        com.seewo.factoryaging.opengl3d.j.c cVarA = com.seewo.factoryaging.opengl3d.j.b.a();
        cVarA.T("axis");
        this.e = cVarA;
        this.f = new HashMap();
        this.f327g = new HashMap();
        this.f328h = new HashMap();
        this.f329i = new HashMap();
        this.f330j = new float[16];
        this.f331k = new float[16];
        this.f332l = new float[16];
        this.f333m = new float[16];
        this.n = new float[4];
        this.o = new float[16];
        this.p = new float[16];
        this.q = new float[16];
        this.r = new float[16];
        this.s = new float[16];
        this.t = new float[16];
        this.u = new HashMap();
        this.v = new com.seewo.factoryaging.opengl3d.h.c();
        this.w = false;
        this.x = cVar;
        this.d = new com.seewo.factoryaging.opengl3d.h.f(context);
    }

    private void c(float[] fArr, float[] fArr2, float[] fArr3, float[] fArr4, float[] fArr5) {
        com.seewo.factoryaging.opengl3d.j.c cVar;
        if (this.x.r()) {
            com.seewo.factoryaging.opengl3d.j.a aVarC = this.d.c();
            Matrix.multiplyMM(this.f331k, 0, fArr, 0, this.x.i().p(), 0);
            Matrix.multiplyMV(fArr4, 0, this.f331k, 0, this.x.j(), 0);
            aVarC.a(this.x.i(), fArr2, fArr, -1, fArr4, fArr5);
        }
        if (this.x.p()) {
            com.seewo.factoryaging.opengl3d.j.a aVarC2 = this.d.c();
            com.seewo.factoryaging.opengl3d.j.c cVar2 = this.e;
            aVarC2.b(cVar2, fArr2, fArr, cVar2.e(), this.e.i(), -1, fArr4, fArr5);
        }
        if (this.x.k().isEmpty()) {
            return;
        }
        List<com.seewo.factoryaging.opengl3d.j.c> listK = this.x.k();
        for (int i2 = 0; i2 < listK.size(); i2++) {
            com.seewo.factoryaging.opengl3d.j.c cVar3 = null;
            try {
                cVar = listK.get(i2);
            } catch (Exception e) {
                e = e;
            }
            try {
                com.seewo.factoryaging.opengl3d.j.a aVarA = this.d.a(cVar, this.x.v(), this.x.r(), this.x.o(), this.x.q());
                if (aVarA != null) {
                    if (!this.u.containsKey(cVar)) {
                        Log.i("ModelRenderer", "Model '" + cVar.m() + "'. Drawer " + aVarA.getClass().getName());
                        this.u.put(cVar, Boolean.TRUE);
                    }
                    boolean zK = cVar.K();
                    Integer num = this.f327g.get(cVar.D());
                    if (num == null && cVar.D() != null) {
                        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(cVar.D());
                        Integer numValueOf = Integer.valueOf(com.seewo.factoryaging.opengl3d.k.b.d(byteArrayInputStream));
                        byteArrayInputStream.close();
                        this.f327g.put(cVar.D(), numValueOf);
                        num = numValueOf;
                    }
                    if (num == null) {
                        num = -1;
                    }
                    if (cVar.e() == 0) {
                        this.d.c().c(cVar, fArr2, fArr, 0, fArr4);
                    } else if (this.x.w() && cVar.e() != 0 && cVar.e() != 1 && cVar.e() != 3 && cVar.e() != 2) {
                        try {
                            com.seewo.factoryaging.opengl3d.j.c cVarF = this.f.get(cVar);
                            if (cVarF == null || zK) {
                                Log.i("ModelRenderer", "Generating wireframe model...");
                                cVarF = com.seewo.factoryaging.opengl3d.j.b.f(cVar);
                                this.f.put(cVar, cVarF);
                            }
                            com.seewo.factoryaging.opengl3d.j.c cVar4 = cVarF;
                            aVarA.b(cVar4, fArr2, fArr, cVar4.e(), cVar4.i(), num.intValue(), fArr4, fArr5);
                        } catch (Error e2) {
                            Log.e("ModelRenderer", e2.getMessage(), e2);
                        }
                    } else if (this.x.t() || cVar.l() == null || !cVar.l().e()) {
                        aVarA.b(cVar, fArr2, fArr, 0, cVar.i(), num.intValue(), fArr4, fArr5);
                    } else if (this.x.u() && (cVar instanceof com.seewo.factoryaging.opengl3d.h.a) && ((com.seewo.factoryaging.opengl3d.h.a) cVar).k0() != null) {
                        com.seewo.factoryaging.opengl3d.j.c cVarE = this.f329i.get(cVar);
                        if (cVarE == null) {
                            cVarE = com.seewo.factoryaging.opengl3d.j.b.e((com.seewo.factoryaging.opengl3d.h.a) cVar);
                            this.f329i.put(cVar, cVarE);
                        }
                        this.v.i(cVarE, this.x.x());
                        this.d.a(cVarE, false, this.x.r(), this.x.o(), this.x.q()).a(cVarE, fArr2, fArr, -1, fArr4, fArr5);
                    } else {
                        aVarA.a(cVar, fArr2, fArr, num.intValue(), fArr4, fArr5);
                    }
                    if (this.x.s()) {
                        com.seewo.factoryaging.opengl3d.j.c cVarC = this.f328h.get(cVar);
                        if (cVarC == null || zK) {
                            cVarC = com.seewo.factoryaging.opengl3d.j.b.c(cVar);
                            if (cVarC != null) {
                                this.f328h.put(cVar, cVarC);
                            }
                        }
                        com.seewo.factoryaging.opengl3d.j.c cVar5 = cVarC;
                        if (cVar5 != null) {
                            this.d.b().c(cVar5, fArr2, fArr, -1, null);
                        }
                    }
                }
            } catch (Exception e3) {
                e = e3;
                cVar3 = cVar;
                Log.e("ModelRenderer", "There was a problem rendering the object '" + cVar3.m() + "':" + e.getMessage(), e);
            }
        }
    }

    public float a() {
        return 100.0f;
    }

    public float b() {
        return 1.0f;
    }

    @Override // android.opengl.GLSurfaceView.Renderer
    public void onDrawFrame(GL10 gl10) {
        if (this.w) {
            return;
        }
        try {
            GLES20.glViewport(0, 0, this.a, this.b);
            GLES20.glScissor(0, 0, this.a, this.b);
            GLES20.glClear(16640);
        } catch (Exception e) {
            Log.e("ModelRenderer", "Fatal exception: " + e.getMessage(), e);
            this.w = true;
        }
        if (this.x == null) {
            return;
        }
        if (this.x.n()) {
            GLES20.glEnable(3042);
            GLES20.glBlendFunc(1, 771);
        } else {
            GLES20.glDisable(3042);
        }
        this.x.A();
        com.seewo.factoryaging.opengl3d.h.e eVarH = this.x.h();
        if (eVarH.d()) {
            float f = this.a / this.b;
            if (this.x.y()) {
                com.seewo.factoryaging.opengl3d.h.e[] eVarArrH = eVarH.h(z);
                com.seewo.factoryaging.opengl3d.h.e eVar = eVarArrH[0];
                com.seewo.factoryaging.opengl3d.h.e eVar2 = eVarArrH[1];
                Matrix.setLookAtM(this.o, 0, eVar.a, eVar.b, eVar.c, eVar.d, eVar.e, eVar.f, eVar.f335g, eVar.f336h, eVar.f337i);
                Matrix.setLookAtM(this.r, 0, eVar2.a, eVar2.b, eVar2.c, eVar2.d, eVar2.e, eVar2.f, eVar2.f335g, eVar2.f336h, eVar2.f337i);
                if (this.x.m()) {
                    float f2 = -f;
                    Matrix.frustumM(this.s, 0, f2, f, -1.0f, 1.0f, b(), a());
                    Matrix.frustumM(this.p, 0, f2, f, -1.0f, 1.0f, b(), a());
                } else if (this.x.z()) {
                    float f3 = (this.a / 2.0f) / this.b;
                    float f4 = -f3;
                    Matrix.frustumM(this.s, 0, f4, f3, -1.0f, 1.0f, b(), a());
                    Matrix.frustumM(this.p, 0, f4, f3, -1.0f, 1.0f, b(), a());
                }
                Matrix.multiplyMM(this.q, 0, this.p, 0, this.o, 0);
                Matrix.multiplyMM(this.t, 0, this.s, 0, this.r, 0);
            } else {
                Matrix.setLookAtM(this.f330j, 0, eVarH.a, eVarH.b, eVarH.c, eVarH.d, eVarH.e, eVarH.f, eVarH.f335g, eVarH.f336h, eVarH.f337i);
                Matrix.multiplyMM(this.f333m, 0, this.f332l, 0, this.f330j, 0);
            }
            eVarH.g(false);
        }
        if (this.x.y()) {
            return;
        }
        try {
            if (this.c == 0) {
                GLES20.glClearColor(0.0f, 0.0f, 1.0f, 0.5f);
                c(this.f330j, this.f332l, this.f333m, this.n, A);
                Thread.sleep(200L);
            } else if (this.c == 1) {
                GLES20.glClearColor(0.0f, 1.0f, 0.0f, 0.5f);
                c(this.f330j, this.f332l, this.f333m, this.n, B);
                Thread.sleep(200L);
            } else if (this.c == 2) {
                GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.5f);
                c(this.f330j, this.f332l, this.f333m, this.n, C);
                Thread.sleep(200L);
            } else if (this.c == 3) {
                GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
                c(this.f330j, this.f332l, this.f333m, this.n, D);
                Thread.sleep(200L);
            } else if (this.c == 4) {
                GLES20.glClearColor(0.0f, 0.0f, 1.0f, 0.5f);
                c(this.f330j, this.f332l, this.f333m, this.n, E);
                Thread.sleep(200L);
            } else {
                GLES20.glClearColor(1.0f, 1.0f, 1.0f, 0.5f);
                c(this.f330j, this.f332l, this.f333m, this.n, A);
                Thread.sleep(200L);
            }
            int i2 = this.c + 1;
            this.c = i2;
            if (i2 > 4) {
                this.c = 0;
                return;
            }
            return;
        } catch (Exception e2) {
            Log.getStackTraceString(e2);
            return;
        }
        Log.e("ModelRenderer", "Fatal exception: " + e.getMessage(), e);
        this.w = true;
    }

    @Override // android.opengl.GLSurfaceView.Renderer
    public void onSurfaceChanged(GL10 gl10, int i2, int i3) {
        this.a = i2;
        this.b = i3;
        GLES20.glViewport(0, 0, i2, i3);
        float f = i2 / i3;
        String str = y;
        StringBuilder sb = new StringBuilder();
        sb.append("projection: [");
        float f2 = -f;
        sb.append(f2);
        sb.append(",");
        sb.append(f);
        sb.append(",-1,1]-near/far[1,10]");
        Log.d(str, sb.toString());
        Matrix.frustumM(this.f332l, 0, f2, f, -1.0f, 1.0f, b(), a());
        Matrix.frustumM(this.s, 0, f2, f, -1.0f, 1.0f, b(), a());
        Matrix.frustumM(this.p, 0, f2, f, -1.0f, 1.0f, b(), a());
    }

    @Override // android.opengl.GLSurfaceView.Renderer
    public void onSurfaceCreated(GL10 gl10, EGLConfig eGLConfig) {
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
        GLES20.glEnable(2929);
        GLES20.glEnable(InvokeCmd.CMD_NETWORK_WOW_SET_ENABLE);
    }
}
