Updates for emission handling.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4050 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user