From e5496065dc92fc6f7d37abd6459247cb8fc4274b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 24 Apr 2006 18:08:44 +0000 Subject: [PATCH] Updates for emission handling. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4050 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../jme/model/EmissionController.java | 62 +++++++++++++++++++ src/java/com/threerings/jme/model/Model.java | 11 ++++ .../threerings/jme/model/ModelController.java | 7 +++ .../threerings/jme/model/TextureProvider.java | 4 ++ .../com/threerings/jme/tools/ModelViewer.java | 12 +++- 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/java/com/threerings/jme/model/EmissionController.java diff --git a/src/java/com/threerings/jme/model/EmissionController.java b/src/java/com/threerings/jme/model/EmissionController.java new file mode 100644 index 000000000..2c305abae --- /dev/null +++ b/src/java/com/threerings/jme/model/EmissionController.java @@ -0,0 +1,62 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.jme.model; + +import com.jme.math.Vector3f; +import com.jme.scene.Geometry; +import com.jme.scene.Spatial; +import com.jme.util.geom.BufferUtils; + +/** + * A model controller whose target represents an emitter. + */ +public abstract class EmissionController extends ModelController +{ + @Override // documentation inherited + public void init (Model model) + { + super.init(model); + _target.setCullMode(Spatial.CULL_ALWAYS); + } + + /** + * Determines the current location of the emitter in world coordinates. + */ + protected void getEmitterLocation (Vector3f result) + { + result.set(_target.getWorldBound().getCenter()); + } + + /** + * Determines the current direction of the emitter in world coordinates. + */ + protected void getEmitterDirection (Vector3f result) + { + if (_target instanceof Geometry) { + BufferUtils.populateFromBuffer(result, + ((Geometry)_target).getNormalBuffer(), 0); + } else { + result.set(0f, -1f, 0f); + } + _target.getWorldRotation().multLocal(result); + } +} diff --git a/src/java/com/threerings/jme/model/Model.java b/src/java/com/threerings/jme/model/Model.java index b71b1d2ec..759a51a55 100644 --- a/src/java/com/threerings/jme/model/Model.java +++ b/src/java/com/threerings/jme/model/Model.java @@ -455,6 +455,17 @@ public class Model extends ModelNode } } + @Override // documentation inherited + public void resolveTextures (TextureProvider tprov) + { + super.resolveTextures(tprov); + for (Object ctrl : getControllers()) { + if (ctrl instanceof ModelController) { + ((ModelController)ctrl).resolveTextures(tprov); + } + } + } + /** * Creates and returns a new instance of this model. */ diff --git a/src/java/com/threerings/jme/model/ModelController.java b/src/java/com/threerings/jme/model/ModelController.java index ad458f5c7..7f9d128cc 100644 --- a/src/java/com/threerings/jme/model/ModelController.java +++ b/src/java/com/threerings/jme/model/ModelController.java @@ -59,6 +59,13 @@ public abstract class ModelController extends Controller Collections.addAll(_animations, anims); } + /** + * Resolves any textures required by the controller. + */ + public void resolveTextures (TextureProvider tprov) + { + } + /** * Initializes this controller. */ diff --git a/src/java/com/threerings/jme/model/TextureProvider.java b/src/java/com/threerings/jme/model/TextureProvider.java index 3b1126b5f..9734f7ad2 100644 --- a/src/java/com/threerings/jme/model/TextureProvider.java +++ b/src/java/com/threerings/jme/model/TextureProvider.java @@ -30,6 +30,10 @@ public interface TextureProvider { /** * Returns a texture state containing the named texture. + * + * @param name the name of the texture, which will be interpreted as an + * absolute resource path if it starts with a forward slash; otherwise, + * as a relative resource path */ public TextureState getTexture (String name); } diff --git a/src/java/com/threerings/jme/tools/ModelViewer.java b/src/java/com/threerings/jme/tools/ModelViewer.java index b6b27084a..ed9fb49fa 100644 --- a/src/java/com/threerings/jme/tools/ModelViewer.java +++ b/src/java/com/threerings/jme/tools/ModelViewer.java @@ -77,6 +77,7 @@ import com.samskivert.swing.GroupLayout; import com.samskivert.swing.Spacer; import com.samskivert.util.Config; +import com.threerings.resource.ResourceManager; import com.threerings.util.MessageBundle; import com.threerings.util.MessageManager; @@ -107,6 +108,7 @@ public class ModelViewer extends JmeCanvasApp public ModelViewer (String path) { super(1024, 768); + _rsrcmgr = new ResourceManager("rsrc"); _msg = new MessageManager("rsrc.i18n").getBundle("jme.viewer"); _path = path; @@ -367,7 +369,12 @@ public class ModelViewer extends JmeCanvasApp public TextureState getTexture (String name) { TextureState tstate = _tstates.get(name); if (tstate == null) { - File file = new File(dir, name); + File file; + if (name.startsWith("/")) { + file = _rsrcmgr.getResourceFile(name.substring(1)); + } else { + file = new File(dir, name); + } Texture tex = TextureManager.loadTexture(file.toString(), Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR); if (tex == null) { @@ -408,6 +415,9 @@ public class ModelViewer extends JmeCanvasApp FastMath.pow(2f, _animspeed.getValue() / 50f)); } + /** The resource manager. */ + protected ResourceManager _rsrcmgr; + /** The translation bundle. */ protected MessageBundle _msg;