* Mesh.getTriangle() now supports 32bit index buffers and no index buffers
* Fix small logging issue in InputManager * Added stream-cache feature to streaming audio * Additional javadoc git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7515 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
cbefb99eed
commit
3a938b7dc9
@ -32,6 +32,11 @@
|
|||||||
|
|
||||||
package com.jme3.audio;
|
package com.jme3.audio;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for managing AL (Audio Library) objects.
|
||||||
|
*
|
||||||
|
* @author Kirill Vainer
|
||||||
|
*/
|
||||||
public abstract class ALObject {
|
public abstract class ALObject {
|
||||||
|
|
||||||
protected int id = -1;
|
protected int id = -1;
|
||||||
|
@ -38,10 +38,10 @@ import java.nio.ByteBuffer;
|
|||||||
/**
|
/**
|
||||||
* An <code>AudioBuffer</code> is an implementation of AudioData
|
* An <code>AudioBuffer</code> is an implementation of AudioData
|
||||||
* where the audio is buffered (stored in memory). All parts of it
|
* where the audio is buffered (stored in memory). All parts of it
|
||||||
* are accessable at any time. <br/>
|
* are accessible at any time. <br/>
|
||||||
* AudioBuffers are useful for short sounds, like effects, etc.
|
* AudioBuffers are useful for short sounds, like effects, etc.
|
||||||
*
|
*
|
||||||
* @author Kirill
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public class AudioBuffer extends AudioData {
|
public class AudioBuffer extends AudioData {
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ package com.jme3.audio;
|
|||||||
* are to be stored entirely in memory, while long audio files (music) is
|
* are to be stored entirely in memory, while long audio files (music) is
|
||||||
* streamed from the hard drive as it is played.
|
* streamed from the hard drive as it is played.
|
||||||
*
|
*
|
||||||
* @author Kirill
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public abstract class AudioData extends ALObject {
|
public abstract class AudioData extends ALObject {
|
||||||
|
|
||||||
|
@ -42,11 +42,28 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* <code>AudioKey</code> is extending AssetKey by holding stream flag.
|
* <code>AudioKey</code> is extending AssetKey by holding stream flag.
|
||||||
*
|
*
|
||||||
* @author Kirill
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public class AudioKey extends AssetKey<AudioData> {
|
public class AudioKey extends AssetKey<AudioData> {
|
||||||
|
|
||||||
private boolean stream;
|
private boolean stream;
|
||||||
|
private boolean streamCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new AudioKey.
|
||||||
|
*
|
||||||
|
* @param name Name of the asset
|
||||||
|
* @param stream If true, the audio will be streamed from harddrive,
|
||||||
|
* otherwise it will be buffered entirely and then played.
|
||||||
|
* @param streamCache If stream is true, then this specifies if
|
||||||
|
* the stream cache is used. When enabled, the audio stream will
|
||||||
|
* be read entirely but not decoded, allowing features such as
|
||||||
|
* seeking, determining duration and looping.
|
||||||
|
*/
|
||||||
|
public AudioKey(String name, boolean stream, boolean streamCache){
|
||||||
|
this(name, stream);
|
||||||
|
this.streamCache = streamCache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new AudioKey
|
* Create a new AudioKey
|
||||||
@ -70,15 +87,35 @@ public class AudioKey extends AssetKey<AudioData> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return name + (stream ? "/S" : "");
|
return name + (stream ?
|
||||||
|
(streamCache ?
|
||||||
|
" (Stream/Cache)" :
|
||||||
|
" (Stream)") :
|
||||||
|
" (Buffer)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if the loaded audio should be a {@link AudioStream} or
|
||||||
|
* false if it should be a {@link AudioBuffer}.
|
||||||
|
*/
|
||||||
public boolean isStream() {
|
public boolean isStream() {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies if the stream cache is used.
|
||||||
|
*
|
||||||
|
* When enabled, the audio stream will
|
||||||
|
* be read entirely but not decoded, allowing features such as
|
||||||
|
* seeking, looping and determining duration.
|
||||||
|
*/
|
||||||
|
public boolean useStreamCache(){
|
||||||
|
return streamCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean shouldCache(){
|
public boolean shouldCache(){
|
||||||
return !stream;
|
return !stream && !streamCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,6 +123,7 @@ public class AudioKey extends AssetKey<AudioData> {
|
|||||||
super.write(ex);
|
super.write(ex);
|
||||||
OutputCapsule oc = ex.getCapsule(this);
|
OutputCapsule oc = ex.getCapsule(this);
|
||||||
oc.write(stream, "do_stream", false);
|
oc.write(stream, "do_stream", false);
|
||||||
|
oc.write(streamCache, "use_stream_cache", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,6 +131,7 @@ public class AudioKey extends AssetKey<AudioData> {
|
|||||||
super.read(im);
|
super.read(im);
|
||||||
InputCapsule ic = im.getCapsule(this);
|
InputCapsule ic = im.getCapsule(this);
|
||||||
stream = ic.readBoolean("do_stream", false);
|
stream = ic.readBoolean("do_stream", false);
|
||||||
|
streamCache = ic.readBoolean("use_stream_cache", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -428,10 +428,6 @@ public class AudioNode extends Node {
|
|||||||
* @see AudioNode#setDryFilter(com.jme3.audio.Filter)
|
* @see AudioNode#setDryFilter(com.jme3.audio.Filter)
|
||||||
*/
|
*/
|
||||||
public void setReverbFilter(Filter reverbFilter) {
|
public void setReverbFilter(Filter reverbFilter) {
|
||||||
if (this.reverbFilter != null) {
|
|
||||||
throw new IllegalStateException("Filter already set");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reverbFilter = reverbFilter;
|
this.reverbFilter = reverbFilter;
|
||||||
if (channel >= 0)
|
if (channel >= 0)
|
||||||
renderer.updateSourceParam(this, AudioParam.ReverbFilter);
|
renderer.updateSourceParam(this, AudioParam.ReverbFilter);
|
||||||
|
@ -47,9 +47,9 @@ import java.io.InputStream;
|
|||||||
public class AudioStream extends AudioData implements Closeable{
|
public class AudioStream extends AudioData implements Closeable{
|
||||||
|
|
||||||
protected InputStream in;
|
protected InputStream in;
|
||||||
private float duration = -1f;
|
protected float duration = -1f;
|
||||||
private boolean open = false;
|
protected boolean open = false;
|
||||||
private int[] ids;
|
protected int[] ids;
|
||||||
|
|
||||||
public AudioStream(){
|
public AudioStream(){
|
||||||
}
|
}
|
||||||
@ -104,6 +104,7 @@ public class AudioStream extends AudioData implements Closeable{
|
|||||||
throw new RuntimeException("Don't use getId() on streams");
|
throw new RuntimeException("Don't use getId() on streams");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setId(int id){
|
public void setId(int id){
|
||||||
throw new RuntimeException("Don't use setId() on streams");
|
throw new RuntimeException("Don't use setId() on streams");
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ public class InputManager implements RawInputListener {
|
|||||||
names.add(mapping);
|
names.add(mapping);
|
||||||
mapping.triggers.add(hash);
|
mapping.triggers.add(hash);
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.WARNING, "Attempted to add mapping '{0}' twice to trigger.", mappingName);
|
logger.log(Level.WARNING, "Attempted to add mapping \"{0}\" twice to trigger.", mappingName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ import com.jme3.math.Triangle;
|
|||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.scene.VertexBuffer.*;
|
import com.jme3.scene.VertexBuffer.*;
|
||||||
|
import com.jme3.scene.mesh.VirtualIndexBuffer;
|
||||||
|
import com.jme3.scene.mesh.WrappedIndexBuffer;
|
||||||
import com.jme3.util.BufferUtils;
|
import com.jme3.util.BufferUtils;
|
||||||
import com.jme3.util.IntMap;
|
import com.jme3.util.IntMap;
|
||||||
import com.jme3.util.IntMap.Entry;
|
import com.jme3.util.IntMap.Entry;
|
||||||
@ -455,25 +457,27 @@ public class Mesh implements Savable, Cloneable {
|
|||||||
|
|
||||||
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
|
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
|
||||||
VertexBuffer pb = getBuffer(Type.Position);
|
VertexBuffer pb = getBuffer(Type.Position);
|
||||||
VertexBuffer ib = getBuffer(Type.Index);
|
|
||||||
|
IndexBuffer ib = getIndexBuffer();
|
||||||
|
if (ib == null){
|
||||||
|
ib = new VirtualIndexBuffer(vertCount, mode);
|
||||||
|
}else if (mode != Mode.Triangles){
|
||||||
|
ib = new WrappedIndexBuffer(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (pb.getFormat() == Format.Float){
|
if (pb.getFormat() == Format.Float){
|
||||||
FloatBuffer fpb = (FloatBuffer) pb.getData();
|
FloatBuffer fpb = (FloatBuffer) pb.getData();
|
||||||
|
|
||||||
if (ib.getFormat() == Format.UnsignedShort){
|
// aquire triangle's vertex indices
|
||||||
// accepted format for buffers
|
int vertIndex = index * 3;
|
||||||
ShortBuffer sib = (ShortBuffer) ib.getData();
|
int vert1 = ib.get(vertIndex);
|
||||||
|
int vert2 = ib.get(vertIndex+1);
|
||||||
|
int vert3 = ib.get(vertIndex+2);
|
||||||
|
|
||||||
// aquire triangle's vertex indices
|
BufferUtils.populateFromBuffer(v1, fpb, vert1);
|
||||||
int vertIndex = index * 3;
|
BufferUtils.populateFromBuffer(v2, fpb, vert2);
|
||||||
int vert1 = sib.get(vertIndex);
|
BufferUtils.populateFromBuffer(v3, fpb, vert3);
|
||||||
int vert2 = sib.get(vertIndex+1);
|
|
||||||
int vert3 = sib.get(vertIndex+2);
|
|
||||||
|
|
||||||
BufferUtils.populateFromBuffer(v1, fpb, vert1);
|
|
||||||
BufferUtils.populateFromBuffer(v2, fpb, vert2);
|
|
||||||
BufferUtils.populateFromBuffer(v3, fpb, vert3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,13 @@ import java.nio.Buffer;
|
|||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>WrappedIndexBuffer</code> converts from one representation of mesh
|
||||||
|
* data to another. For example it can be used to read TriangleStrip data
|
||||||
|
* as if it was in Triangle format.
|
||||||
|
*
|
||||||
|
* @author Kirill Vainer
|
||||||
|
*/
|
||||||
public class WrappedIndexBuffer extends VirtualIndexBuffer {
|
public class WrappedIndexBuffer extends VirtualIndexBuffer {
|
||||||
|
|
||||||
private final IndexBuffer ib;
|
private final IndexBuffer ib;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user