3D-рендеринг libgdx, у меня низкий fps - PullRequest
0 голосов
/ 04 ноября 2019

Я не уверен, правильно ли я делаю рендеринг 3D? Ниже приведен метод с моим методом 3D-рендеринга. Когда я запускаю свою игру на настольном компьютере, она работает нормально с 60fps, но когда я запускаю ее на Android, она работает только с 15fps. Когда я комментирую этот метод, я тоже получаю 60 кадров в секунду, поэтому я думаю, что проблема в моем коде 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();
    }

1 Ответ

0 голосов
/ 06 ноября 2019

А что вы думаете о моей модели, создающей код?:

Материал highwayMaterial = new Material (TextureAttribute.createDiffuse (highwayTexture), ColorAttribute.createSpecular (1, 1, 1, 1));long highwayAttributes = VertexAttributes.Usage.Position |VertexAttributes.Usage.Normal |VertexAttributes.Usage.TextureCoordinates;highway = modelBuilder.createBox (30f, 0.01f, 60f, highwayMaterial, highwayAttributes);highwayInstance = новый ModelInstance (шоссе, -10, 0, 0);highway2Instance = new ModelInstance (шоссе, -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.01f, 0);
    highwayLine2 = new ModelInstance(highwayLine, -16.17647058823529f, 0.01f, 0);
    highwayLine3 = new ModelInstance(highwayLine, -12.64705882352941f, 0.01f, 0);
    highwayLine4 = new ModelInstance(highwayLine, -7.352941176470588f, 0.01f, 0);
    highwayLine5 = new ModelInstance(highwayLine, -3.823529411764705f, 0.01f, 0);
    highwayLine6 = new ModelInstance(highwayLine, 1.470588235294118f, 0.01f, 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, 60f, aroundHighwayMaterial, theAttributes);
    aroundHighwayInstance1 = new ModelInstance(aroundHighway, -25.5f, 0f, 0f);
    aroundHighwayInstance2 = new ModelInstance(aroundHighway, 5.5f, 0f, 0f);
    highwayLines.add(aroundHighwayInstance1);
    highwayLines.add(aroundHighwayInstance2);

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

    metronomeFirstModel = modelBuilder.createBox(30f, 0.02f, 0.6f, metronomeMaterial, theAttributes);
    metronomeModel = modelBuilder.createBox(30f, 0.02f, 0.2f, metronomeMaterial, theAttributes);
    snareNote = modelBuilder.createBox(3.176470588235295f, 0.5f, 1f, snareMaterial, theAttributes);
    hiHatNote = modelBuilder.createCone(4.94f, 1f, 2f, 8, hiHatMaterial, theAttributes);
    tom1Note = modelBuilder.createBox(3.176470588235295f, 0.5f, 1f, hiHatMaterial, theAttributes);
    rideNote = modelBuilder.createCone(4.94f, 1f, 2f, 8, rideMaterial, theAttributes);
    tom2Note = modelBuilder.createBox(3.176470588235295f, 0.5f, 1f, rideMaterial, theAttributes);
    crashNote = modelBuilder.createCone(4.94f, 1f, 2f, 8, crashMaterial, theAttributes);
    tom3Note = modelBuilder.createBox(3.176470588235295f, 0.5f, 1f, crashMaterial, theAttributes);
    Material bassMaterial = new Material(ColorAttribute.createDiffuse(Color.CYAN));
    bassNote = modelBuilder.createBox(30f, 0.2f, 0.4f, bassMaterial, theAttributes);
...