⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 particleappearancepanel.java

📁 java 3d game jme 工程开发源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    oldGeom.getNumParticles());
            newGeom = pPoints;
            pPoints.setPointSize(5);
            pPoints.setAntialiased(true);
        } else if (newType == ParticleSystem.ParticleType.Line) {
            newGeom = ParticleFactory.buildLineParticles(oldGeom.getName(),
                oldGeom.getNumParticles());
        } else {
            newGeom = ParticleFactory.buildParticles(oldGeom.getName(),
                oldGeom.getNumParticles(), newType);
        }
        // copy appearance parameters
        newGeom.setVelocityAligned(oldGeom.isVelocityAligned());
        newGeom.setStartColor(oldGeom.getStartColor().clone());
        newGeom.setEndColor(oldGeom.getEndColor().clone());
        newGeom.setStartTexIndex(oldGeom.getStartTexIndex());
        newGeom.setStartSize(oldGeom.getStartSize());
        newGeom.setEndSize(oldGeom.getEndSize());
        newGeom.setStartMass(oldGeom.getStartMass());
        newGeom.setEndMass(oldGeom.getEndMass());
        newGeom.setStartSpin(oldGeom.getStartSpin());
        newGeom.setEndSpin(oldGeom.getEndSpin());
        newGeom.setRamp(oldGeom.getRamp());
        newGeom.setTexQuantity(oldGeom.getTexQuantity());
        
        // copy origin parameters
        newGeom.setLocalTranslation(oldGeom.getLocalTranslation());
        newGeom.setLocalRotation(oldGeom.getLocalRotation());
        newGeom.setLocalScale(oldGeom.getLocalScale());
        newGeom.setOriginOffset(oldGeom.getOriginOffset());
        newGeom.setGeometry(oldGeom.getLine());
        newGeom.setGeometry(oldGeom.getRectangle());
        newGeom.setGeometry(oldGeom.getRing());
        newGeom.setEmitType(oldGeom.getEmitType());
        
        // copy emission parameters
        newGeom.setRotateWithScene(oldGeom.isRotateWithScene());
        newGeom.setEmissionDirection(oldGeom.getEmissionDirection());
        newGeom.setMinimumAngle(oldGeom.getMinimumAngle());
        newGeom.setMaximumAngle(oldGeom.getMaximumAngle());
        newGeom.setInitialVelocity(oldGeom.getInitialVelocity());
        
        // copy flow parameters
        newGeom.setControlFlow(oldGeom.getParticleController().isControlFlow());
        newGeom.setReleaseRate(oldGeom.getReleaseRate());
        newGeom.setReleaseVariance(oldGeom.getReleaseVariance());
        newGeom.setRepeatType(oldGeom.getParticleController().getRepeatType());
        
        // copy world parameters
        newGeom.setSpeed(oldGeom.getParticleController().getSpeed());
        newGeom.setMinimumLifeTime(oldGeom.getMinimumLifeTime());
        newGeom.setMaximumLifeTime(oldGeom.getMaximumLifeTime());
        newGeom.getParticleController().setPrecision(
                oldGeom.getParticleController().getPrecision());
        
        // copy influence parameters
        ArrayList<ParticleInfluence> infs = oldGeom.getInfluences();
        if (infs != null) {
            for (ParticleInfluence inf : infs) {
                newGeom.addInfluence(inf);
            }
        }
        
        // copy render states
        for (RenderState.StateType type : RenderState.StateType.values()) {
            RenderState rs = oldGeom.getRenderState(type);
            if (rs != null) {
                newGeom.setRenderState(rs);
            }
        }
        
        requestParticleSystemOverwrite(newGeom);
    }
    
    protected abstract void requestParticleSystemOverwrite(ParticleSystem newParticles);

    private void changeTexture() {
        try {
            int result = textureChooser.showOpenDialog(this);
            if (result == JFileChooser.CANCEL_OPTION) {
                return;
            }
            File textFile = textureChooser.getSelectedFile();
            prefs.put("texture_dir", textFile.getParent());

            newTexture = textFile;
            
            GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(new Callable<Object>() {
                public Object call() throws Exception{
                    loadApplyTexture();
                    return null;
                }
            });

            ImageIcon icon = new ImageIcon(
                getToolkit().createImage(textFile.getAbsolutePath()));
            imageLabel.setIcon(icon);
            validate();
        } catch (Exception ex) {
            logger.logp(Level.SEVERE, this.getClass().toString(), "changeTexture()", "Exception",
                    ex);
        }
    }

    private void initTextureChooser() {
        String tdir = prefs.get("texture_dir", null);
        if (tdir != null) {
            textureChooser.setCurrentDirectory(new File(tdir));
        }
    }

    private void loadApplyTexture() throws MalformedURLException {
        TextureState ts = (TextureState)getEdittedParticles().getRenderState(RenderState.StateType.Texture);
        TextureManager.clearCache();
        ts.setTexture(
                TextureManager.loadTexture(
                        newTexture.toURI().toURL(),
                        Texture.MinificationFilter.BilinearNearestMipMap,
                        Texture.MagnificationFilter.Bilinear));
        ts.setEnabled(true);
        getEdittedParticles().setRenderState(ts);
        getEdittedParticles().updateRenderState();
        newTexture = null;
    }

    private void updateBlendState(boolean additive) {
        BlendState as = (BlendState)getEdittedParticles().getRenderState(RenderState.StateType.Blend);
        if (as == null) {
            as = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
            as.setBlendEnabled(true);
            as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
            as.setTestEnabled(true);
            as.setTestFunction(BlendState.TestFunction.GreaterThan);
            getEdittedParticles().setRenderState(as);
            getEdittedParticles().updateRenderState();
        }
        as.setDestinationFunction(additive ?
            BlendState.DestinationFunction.One : BlendState.DestinationFunction.OneMinusSourceAlpha);
    }

    @Override
    public void updateWidgets() {
        updateRampModel();
        
        ParticleSystem system = getEdittedParticles();
        geomTypeBox.setSelectedItem(system.getParticleType());
        velocityAlignedBox.setSelected(system.isVelocityAligned());
        texPanel.setValue(system.getTexQuantity());
        startTexPanel.setValue(system.getStartTexIndex());

        BlendState as = (BlendState)system.getRenderState(RenderState.StateType.Blend);
        additiveBlendingBox.setSelected(as == null ||
            as.getDestinationFunctionRGB() == BlendState.DestinationFunction.One);
        if (getTexturePanel().isVisible()) {
            Texture tex = null;
            try {
                tex = ((TextureState)system.getRenderState(RenderState.StateType.Texture)).getTexture();
                if (tex != null) {
                    if (tex.getTextureKey() != null && tex.getTextureKey().getLocation() != null)
                        imageLabel.setIcon(
                                new ImageIcon(tex.getTextureKey().getLocation()));
                    else
                        imageLabel.setIcon(
                            new ImageIcon(new URL(tex.getImageLocation())));
                } else {
                    imageLabel.setIcon(null);
                }
            } catch (Exception e) {
                logger.warning("image: "+tex+" : "+ tex != null ? tex.getImageLocation() : "");
            }
        }
    }

    public JCheckBox getAdditiveBlendingBox() {
        return additiveBlendingBox;
    }

    public JPanel getTexturePanel() {
        return texturePanel;
    }
    
    public class StartRamp extends RampEntry {

        private ParticleSystem particles;

        public StartRamp(ParticleSystem particles) {
            super(-1);
            this.particles = particles;
            setColor(particles.getStartColor());
            setSize(particles.getStartSize());
            setMass(particles.getStartMass());
            setSpin(particles.getStartSpin());
        }
        
        @Override
        public String toString() {
            return "START: "+super.toString();
        }
        
        @Override
        public void setSize(float size) {
            super.setSize(size);
            particles.setStartSize(size);
        }
        
        @Override
        public void setMass(float mass) {
            super.setMass(mass);
            particles.setStartMass(mass);
        }
        
        @Override
        public void setSpin(float spin) {
            super.setSpin(spin);
            particles.setStartSpin(spin);
        }
        
        @Override
        public void setColor(ColorRGBA color) {
            super.setColor(color);
            particles.setStartColor(color);
        }
    }
    
    public class EndRamp extends RampEntry {

        private ParticleSystem particles;

        public EndRamp(ParticleSystem particles) {
            super(-1);
            this.particles = particles;
            setColor(particles.getEndColor());
            setSize(particles.getEndSize());
            setMass(particles.getEndMass());
            setSpin(particles.getEndSpin());
        }
        
        @Override
        public String toString() {
            return "END: "+super.toString();
        }
        
        @Override
        public void setSize(float size) {
            super.setSize(size);
            particles.setEndSize(size);
        }
        
        @Override
        public void setMass(float mass) {
            super.setMass(mass);
            particles.setEndMass(mass);
        }
        
        @Override
        public void setSpin(float spin) {
            super.setSpin(spin);
            particles.setEndSpin(spin);
        }
        
        @Override
        public void setColor(ColorRGBA color) {
            super.setColor(color);
            particles.setEndColor(color);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -