libgdx 3d渲染,我的fps低

我不确定3d渲染是否正确吗?下面是我的3d渲染方法的一种方法。当我在桌面上运行游戏时,可以60fps正常运行,但是当我在android上运行时,仅可以15fps运行。当我注释掉这种方法时,我也能获得60fps,所以我认为问题出在我的3d渲染代码中。

你能告诉我它是否正确吗?

private void draw3d() {
        gameViewport.apply();

        modelBatch.begin(gameCamera);
        modelBatch.render(highwayInstance,environment);
        modelBatch.render(highway2Instance,environment);
        modelBatch.render(highwayLines,environment);
        modelBatch.render(buttons,environment);
        if (activeMetronomeFirsts.size != 0) {
            int activeMetronomeFirstLength = activeMetronomeFirsts.size;
            for (int i = activeMetronomeFirstLength; --i >= 0;) {
                modelBatch.render(activeMetronomeFirsts.get(i).getMetronomeInstance(),environment);
            }
        }
        if (activeMetronomes.size != 0) {
            int activeMetronomeLength = activeMetronomes.size;
            for (int i = activeMetronomeLength; --i >= 0;) {
                modelBatch.render(activeMetronomes.get(i).getMetronomeInstance(),environment);
            }
        }
        if (activesnares.size != 0) {
            int activesnareLength = activesnares.size;
            for (int i = activesnareLength; --i >= 0;) {
                modelBatch.render(activesnares.get(i).getsnareInstance(),environment);
                //activesnares.get(i).draw(modelBatch);
            }
        }
        if (activeHiHats.size != 0) {
            int activeHiHatLength = activeHiHats.size;
            for (int i = activeHiHatLength; --i >= 0;) {
                modelBatch.render(activeHiHats.get(i).getHiHatInstance(),environment);
            }
        }
        if (activeTom1s.size != 0) {
            int activeTom1Length = activeTom1s.size;
            for (int i = activeTom1Length; --i >= 0;) {
                modelBatch.render(activeTom1s.get(i).getTom1Instance(),environment);
            }
        }
        if (activeRides.size != 0) {
            int activeRideLength = activeRides.size;
            for (int i = activeRideLength; --i >= 0;) {
                modelBatch.render(activeRides.get(i).getRideInstance(),environment);
            }
        }
        if (activeTom2s.size != 0) {
            int activeTom2Length = activeTom2s.size;
            for (int i = activeTom2Length; --i >= 0;) {
                modelBatch.render(activeTom2s.get(i).getTom2Instance(),environment);
            }
        }
        if (activeCrashs.size != 0) {
            int activeCrashLength = activeCrashs.size;
            for (int i = activeCrashLength; --i >= 0;) {
                modelBatch.render(activeCrashs.get(i).getcrashInstance(),environment);
            }
        }
        if (activeTom3s.size != 0) {
            int activeTom3Length = activeTom3s.size;
            for (int i = activeTom3Length; --i >= 0;) {
                modelBatch.render(activeTom3s.get(i).getTom3Instance(),environment);
            }
        }
        if (activeBasses.size != 0) {
            int activeBassLength = activeBasses.size;
            for (int i = activeBassLength; --i >= 0;) {
                modelBatch.render(activeBasses.get(i).getBassInstance(),environment);
            }
        }
        modelBatch.end();
    }
WOSHI555 回答:libgdx 3d渲染,我的fps低

您如何看待我的模型创建代码?

Material HighwayMaterial =新材质(TextureAttribute.createDiffuse(highwayTexture),                 ColorAttribute.createSpecular(1,1,1,1));         long HighwayAttributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;         公路= modelBuilder.createBox(30f,0.01f,60f,公路材料,公路属性);         HighwayInstance =新的ModelInstance(highway,-10,0,0);         Highway2Instance = new ModelInstance(highway,-10,0,-60);

    //model testing
    Material metronomeMaterial = new Material(ColorAttribute.createDiffuse(Color.LIGHT_GRAY));
    long theAttributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal;

    Material highwayLineMaterial = new Material(ColorAttribute.createDiffuse(Color.DARK_GRAY));

    //ještě highway line
    highwayLine = modelBuilder.createBox(0.2f,0.01f,60f,highwayLineMaterial,theAttributes);
    highwayLine1 = new ModelInstance(highwayLine,-21.47058823529412f,0);
    highwayLine2 = new ModelInstance(highwayLine,-16.17647058823529f,0);
    highwayLine3 = new ModelInstance(highwayLine,-12.64705882352941f,0);
    highwayLine4 = new ModelInstance(highwayLine,-7.352941176470588f,0);
    highwayLine5 = new ModelInstance(highwayLine,-3.823529411764705f,0);
    highwayLine6 = new ModelInstance(highwayLine,1.470588235294118f,0);
    highwayLines.add(highwayLine1);
    highwayLines.add(highwayLine2);
    highwayLines.add(highwayLine3);
    highwayLines.add(highwayLine4);
    highwayLines.add(highwayLine5);
    highwayLines.add(highwayLine6);

    Material aroundHighwayMaterial = new Material(ColorAttribute.createDiffuse(Color.LIGHT_GRAY));
    aroundHighway = modelBuilder.createBox(1f,2f,aroundHighwayMaterial,theAttributes);
    aroundHighwayInstance1 = new ModelInstance(aroundHighway,-25.5f,0f,0f);
    aroundHighwayInstance2 = new ModelInstance(aroundHighway,5.5f,0f);
    highwayLines.add(aroundHighwayInstance1);
    highwayLines.add(aroundHighwayInstance2);

    //noteCatcher
    Material aroundButtonsMaterial = new Material(ColorAttribute.createDiffuse(Color.ORANGE),ColorAttribute.createSpecular(1,1,1));
    aroundButtons = modelBuilder.createBox(30f,0.6f,0.3f,aroundButtonsMaterial,theAttributes);
    aroundButtonsInstance1 = new ModelInstance(aroundButtons,-10f,29f);
    aroundButtonsInstance2 = new ModelInstance(aroundButtons,27f);
    //snare button
    drumMetalButton = modelBuilder.createBox(3.529411764705883f,1f,1.5f,theAttributes);
    snareMetalButtonInstance = new ModelInstance(drumMetalButton,-23.23529411764706f,28f);
    buttons.add(snareMetalButtonInstance);
    Material snareMaterial = new Material(ColorAttribute.createDiffuse(Color.RED));
    snareButton = modelBuilder.createBox(3.176470588235295f,1.28f,snareMaterial,theAttributes);
    snareButtonInstance = new ModelInstance(snareButton,0.67f,28f);
    buttons.add(snareButtonInstance);
    //hiHat button
    cymbalMetalButton = modelBuilder.createBox(5.294117647058823f,theAttributes);
    hiHatMetalButtonInstance = new ModelInstance(cymbalMetalButton,-18.82352941176471f,28f);
    buttons.add(hiHatMetalButtonInstance);
    Material hiHatMaterial = new Material(ColorAttribute.createDiffuse(Color.YELLOW));
    hiHatButton = modelBuilder.createBox(4.94f,hiHatMaterial,theAttributes);
    hiHatButtonInstance = new ModelInstance(hiHatButton,28f);
    buttons.add(hiHatButtonInstance);
    //tom1 button
    tom1MetalButtonInstance = new ModelInstance(drumMetalButton,-14.41176470588236f,28f);
    buttons.add(tom1MetalButtonInstance);
    tom1Button = modelBuilder.createBox(3.176470588235295f,theAttributes);
    tom1ButtonInstance = new ModelInstance(tom1Button,28f);
    buttons.add(tom1ButtonInstance);
    //ride button
    rideMetalButtonInstance = new ModelInstance(cymbalMetalButton,-10.00000000000001f,28f);
    buttons.add(rideMetalButtonInstance);
    Material rideMaterial = new Material(ColorAttribute.createDiffuse(Color.BLUE));
    rideButton = modelBuilder.createBox(4.94f,rideMaterial,theAttributes);
    rideButtonInstance = new ModelInstance(rideButton,28f);
    buttons.add(rideButtonInstance);
    //tom2 button
    tom2MetalButtonInstance = new ModelInstance(drumMetalButton,-5.588235294117746f,28f);
    buttons.add(tom2MetalButtonInstance);
    tom2Button = modelBuilder.createBox(3.176470588235295f,theAttributes);
    tom2ButtonInstance = new ModelInstance(tom2Button,28f);
    buttons.add(tom2ButtonInstance);
    //crash button
    crashMetalButtonInstance = new ModelInstance(cymbalMetalButton,-1.176470588235392f,28f);
    buttons.add(crashMetalButtonInstance);
    Material crashMaterial = new Material(ColorAttribute.createDiffuse(Color.GREEN));
    crashButton = modelBuilder.createBox(4.94f,crashMaterial,theAttributes);
    crashButtonInstance = new ModelInstance(crashButton,28f);
    buttons.add(crashButtonInstance);
    //tom3 button
    tom3MetalButtonInstance = new ModelInstance(drumMetalButton,3.235294117646962f,28f);
    buttons.add(tom3MetalButtonInstance);
    tom3Button = modelBuilder.createBox(3.176470588235295f,theAttributes);
    tom3ButtonInstance = new ModelInstance(tom3Button,28f);
    buttons.add(tom3ButtonInstance);
    //for bass
    buttons.add(aroundButtonsInstance1);
    buttons.add(aroundButtonsInstance2);

    metronomeFirstModel = modelBuilder.createBox(30f,0.02f,metronomeMaterial,theAttributes);
    metronomeModel = modelBuilder.createBox(30f,0.2f,theAttributes);
    snareNote = modelBuilder.createBox(3.176470588235295f,0.5f,theAttributes);
    hiHatNote = modelBuilder.createCone(4.94f,8,theAttributes);
    tom1Note = modelBuilder.createBox(3.176470588235295f,theAttributes);
    rideNote = modelBuilder.createCone(4.94f,theAttributes);
    tom2Note = modelBuilder.createBox(3.176470588235295f,theAttributes);
    crashNote = modelBuilder.createCone(4.94f,theAttributes);
    tom3Note = modelBuilder.createBox(3.176470588235295f,theAttributes);
    Material bassMaterial = new Material(ColorAttribute.createDiffuse(Color.CYAN));
    bassNote = modelBuilder.createBox(30f,0.4f,bassMaterial,theAttributes);
本文链接:https://www.f2er.com/3166154.html

大家都在问