Main repository of MikuMikuStudio
修订版 | 636c4543674abe94c411d062d75b65895749a70e (tree) |
---|---|
时间 | 2013-07-07 00:16:12 |
作者 | kobayasi <kobayasi@pscn...> |
Commiter | kobayasi |
add PlaceholderAssets
@@ -0,0 +1,103 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or without | |
6 | + * modification, are permitted provided that the following conditions are | |
7 | + * met: | |
8 | + * | |
9 | + * * Redistributions of source code must retain the above copyright | |
10 | + * notice, this list of conditions and the following disclaimer. | |
11 | + * | |
12 | + * * Redistributions in binary form must reproduce the above copyright | |
13 | + * notice, this list of conditions and the following disclaimer in the | |
14 | + * documentation and/or other materials provided with the distribution. | |
15 | + * | |
16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors | |
17 | + * may be used to endorse or promote products derived from this software | |
18 | + * without specific prior written permission. | |
19 | + * | |
20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
22 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
28 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
29 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | + */ | |
32 | +package com.jme3.util; | |
33 | + | |
34 | +import com.jme3.asset.AssetManager; | |
35 | +import com.jme3.audio.AudioBuffer; | |
36 | +import com.jme3.audio.AudioData; | |
37 | +import com.jme3.material.Material; | |
38 | +import com.jme3.math.ColorRGBA; | |
39 | +import com.jme3.scene.Geometry; | |
40 | +import com.jme3.scene.Spatial; | |
41 | +import com.jme3.scene.shape.Box; | |
42 | +import com.jme3.texture.Image; | |
43 | +import com.jme3.texture.Image.Format; | |
44 | +import java.nio.ByteBuffer; | |
45 | + | |
46 | +public class PlaceholderAssets { | |
47 | + | |
48 | + /** | |
49 | + * Checkerboard of white and red squares | |
50 | + */ | |
51 | + private static final byte[] imageData = { | |
52 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
53 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
54 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
55 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
56 | + | |
57 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
58 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
59 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
60 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
61 | + | |
62 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
63 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
64 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
65 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
66 | + | |
67 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
68 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
69 | + (byte)0xFF, (byte)0x00, (byte)0x00, | |
70 | + (byte)0xFF, (byte)0xFF, (byte)0xFF, | |
71 | + }; | |
72 | + | |
73 | + public static Image getPlaceholderImage(){ | |
74 | + ByteBuffer tempData = BufferUtils.createByteBuffer(3 * 4 * 4); | |
75 | + tempData.put(imageData).flip(); | |
76 | + return new Image(Format.RGB8, 4, 4, tempData); | |
77 | + } | |
78 | + | |
79 | + public static Material getPlaceholderMaterial(AssetManager assetManager){ | |
80 | + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); | |
81 | + mat.setColor("Color", ColorRGBA.Red); | |
82 | + return mat; | |
83 | + } | |
84 | + | |
85 | + public static Spatial getPlaceholderModel(AssetManager assetManager){ | |
86 | + // What should be the size? Nobody knows | |
87 | + // the user's expected scale... | |
88 | + Box box = new Box(1, 1, 1); | |
89 | + Geometry geom = new Geometry("placeholder", box); | |
90 | + geom.setMaterial(getPlaceholderMaterial(assetManager)); | |
91 | + return geom; | |
92 | + } | |
93 | + | |
94 | + public static AudioData getPlaceholderAudio(){ | |
95 | + AudioBuffer audioBuf = new AudioBuffer(); | |
96 | + audioBuf.setupFormat(1, 8, 44100); | |
97 | + ByteBuffer bb = BufferUtils.createByteBuffer(1); | |
98 | + bb.put((byte)0).flip(); | |
99 | + audioBuf.updateData(bb); | |
100 | + return audioBuf; | |
101 | + } | |
102 | + | |
103 | +} |