protected void loadTextures(AssetManager manager) {
   normalTexture =
       (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.png");
   dudvTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/dudv_map.jpg");
   normalTexture.setWrap(WrapMode.Repeat);
   dudvTexture.setWrap(WrapMode.Repeat);
 }
Ejemplo n.º 2
0
  public void loadTileTexture() {
    AssetManager assetManager =
        HexScapeCore.getInstance().getHexScapeJme3Application().getAssetManager();

    File commonFolder = new File(AssetService.COMMON_ASSET_FOLDER, TILES_FOLDER_NAME);
    File gameFolder =
        new File(
            new File(AssetService.ASSET_FOLDER, ConfigurationService.getInstance().getGameFolder()),
            TILES_FOLDER_NAME);
    File commonFile = new File(commonFolder, TEXTURES_FILE_NAME);
    File gameFile = new File(gameFolder, TEXTURES_FILE_NAME);
    BufferedImage bimg = null;
    try {
      if (gameFile.exists() && gameFile.isFile() && gameFile.canRead()) {
        tileTexture = assetManager.loadTexture(gameFile.getPath());
        bimg = ImageIO.read(new File(gameFile.getPath()));
      } else if (commonFile.exists() && commonFile.isFile() && commonFile.canRead()) {
        tileTexture = assetManager.loadTexture(commonFile.getPath());
        bimg = ImageIO.read(new File(gameFile.getPath()));
      } else {
        String resourceLocation = "model/texture/defaultTileTexture.bmp";
        tileTexture = assetManager.loadTexture(resourceLocation);
        bimg = ImageIO.read(ClassLoader.getSystemResourceAsStream(resourceLocation));
      }

      int width = bimg.getWidth();
      int height = bimg.getHeight();

      number = width / height;
    } catch (IOException e) {
      throw new RuntimeException("unable to load texture", e);
    }
  }
Ejemplo n.º 3
0
 private static Texture getTexture(String path) {
   Texture res = textureFileMap.get(path);
   if (res == null) {
     res = am.loadTexture(path);
     textureFileMap.put(path, res);
   }
   return res;
 }
Ejemplo n.º 4
0
 public PAppletDisplayGeometry(
     String name,
     Mesh mesh,
     AssetManager assetmanager,
     PApplet applet,
     int appletFrameWidth,
     int appletFrameHeight,
     boolean frameVisible) {
   this(
       name,
       mesh,
       new Material(assetmanager, "Common/MatDefs/Misc/Unshaded.j3md"),
       assetmanager.loadTexture("Interface/Logo/Monkey.jpg"));
   setupWithPApplet(applet, appletFrameWidth, appletFrameHeight, frameVisible);
 }
Ejemplo n.º 5
0
 protected Texture tryLoadTexture(String name, boolean useDefaultTexture) {
   TextureKey texKey = new TextureKey(folderName + name);
   texKey.setGenerateMips(true);
   Texture texture = null;
   try {
     texture = assetManager.loadTexture(texKey);
     texture.setWrap(WrapMode.Repeat);
     logger.log(Level.INFO, "Loaded {0} for material {1}", new Object[] {texKey, key});
   } catch (AssetNotFoundException ex) {
     logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] {texKey, key});
   }
   if (texture == null && useDefaultTexture) {
     texture = new Texture2D(PlaceholderAssets.getPlaceholderImage());
     texture.setWrap(WrapMode.Repeat);
     texture.setKey(texKey);
   }
   return texture;
 }
  private void initSparks() {
    sparksEmitter = new ParticleEmitter("Spark", ParticleMesh.Type.Triangle, 20);
    Material sparkMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    sparkMat.setTexture("Texture", assetManager.loadTexture("Effects/spark.png"));
    sparksEmitter.setMaterial(sparkMat);
    sparksEmitter.setImagesX(1);
    sparksEmitter.setImagesY(1);
    explosionNode.attachChild(sparksEmitter);

    sparksEmitter.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f)); // orange
    sparksEmitter.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, .5f));
    sparksEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 25, 0));
    sparksEmitter.getParticleInfluencer().setVelocityVariation(1);
    sparksEmitter.setFacingVelocity(true);
    sparksEmitter.setGravity(0, 15, 0);
    sparksEmitter.setStartSize(5f);
    sparksEmitter.setEndSize(5f);
    sparksEmitter.setLowLife(.9f);
    sparksEmitter.setHighLife(1.1f);
    sparksEmitter.setParticlesPerSec(0);
    sparksEmitter.setLocalTranslation(pos);
  }
  private void initEmbers() {
    embersEmitter = new ParticleEmitter("embers", ParticleMesh.Type.Triangle, 50);
    Material embersMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    embersMat.setTexture("Texture", assetManager.loadTexture("Effects/embers.png"));
    embersEmitter.setMaterial(embersMat);
    embersEmitter.setImagesX(1);
    embersEmitter.setImagesY(1);
    explosionNode.attachChild(embersEmitter);

    embersEmitter.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, 1.0f));
    embersEmitter.setEndColor(new ColorRGBA(0, 0, 0, 0.5f));
    embersEmitter.setStartSize(12f);
    embersEmitter.setEndSize(18f);
    embersEmitter.setGravity(0, -.5f, 0);
    embersEmitter.setLowLife(1.8f);
    embersEmitter.setHighLife(5f);
    embersEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3, 0));
    embersEmitter.getParticleInfluencer().setVelocityVariation(.5f);
    embersEmitter.setShape(new EmitterSphereShape(Vector3f.ZERO, 2f));
    embersEmitter.setParticlesPerSec(0);
    embersEmitter.setLocalTranslation(pos);
  }
Ejemplo n.º 8
0
  public static Material getLightingTexture(String texturePath) {
    // We first check if the requested texture exist in the material map
    if (texturesMap.containsKey(texturePath)) {
      return texturesMap.get(texturePath);
    }

    // At this point, we know that the texture doesn't exist.
    // We must create a new material, add it to the map and return it.
    Material res = new Material(am, "Common/MatDefs/Light/Lighting.j3md");
    Texture t = am.loadTexture(texturePath);
    t.setWrap(WrapMode.Repeat);
    t.setAnisotropicFilter(8);
    res.setTexture("DiffuseMap", t);

    res.setFloat("Shininess", 10f); // [0,128]

    // test for envmap
    // TextureCubeMap envmap = new
    // TextureCubeMap(assetManager.loadTexture("Textures/cubemap_reflec.dds").getImage());
    // res.setTexture("EnvMap", envmap);
    // res.setVector3("FresnelParams", new Vector3f(0.05f, 0.18f, 0.11f));
    // res.setVector3("FresnelParams", new Vector3f(0.05f, 0.05f, 0.05f));

    // normal map loading
    // String normalPath = texturePath.replaceAll(".jpg", "norm.jpg");;
    // try {
    // Texture normalMap = assetManager.loadTexture(normalPath);
    // normalMap.setWrap(WrapMode.Repeat);
    // normalMap.setAnisotropicFilter(8);
    // res.setTexture("NormalMap", normalMap);
    // }catch (Exception e) {
    // LogUtil.logger.info("No normal map found for "+texturePath);
    // }

    texturesMap.put(texturePath, res);

    return res;
  }
Ejemplo n.º 9
0
  public static void main(String[] args) {
    AssetManager am = new DesktopAssetManager();

    am.registerLoader(AWTLoader.class.getName(), "png");
    am.registerLoader(WAVLoader.class.getName(), "wav");

    // register absolute locator
    am.registerLocator("/", ClasspathLocator.class.getName());

    // find a sound
    AudioData audio = am.loadAudio("Sound/Effects/Gun.wav");

    // find a texture
    Texture tex = am.loadTexture("Textures/Terrain/Pond/Pond.png");

    if (audio == null) throw new RuntimeException("Cannot find audio!");
    else System.out.println("Audio loaded from Sounds/Effects/Gun.wav");

    if (tex == null) throw new RuntimeException("Cannot find texture!");
    else System.out.println("Texture loaded from Textures/Terrain/Pond/Pond.png");

    System.out.println("Success!");
  }
  private void initSmoke() {
    smokeEmitter = new ParticleEmitter("Smoke emitter", ParticleMesh.Type.Triangle, 20);
    Material smokeMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    smokeMat.setTexture("Texture", assetManager.loadTexture("Effects/smoketrail.png"));
    smokeEmitter.setMaterial(smokeMat);
    smokeEmitter.setImagesX(1);
    smokeEmitter.setImagesY(3);
    smokeEmitter.setSelectRandomImage(true);
    explosionNode.attachChild(smokeEmitter);

    smokeEmitter.setStartColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 1f));
    smokeEmitter.setEndColor(new ColorRGBA(.1f, 0.1f, 0.1f, .5f));
    smokeEmitter.setLowLife(4f);
    smokeEmitter.setHighLife(4f);
    smokeEmitter.setGravity(0, 2, 0);
    smokeEmitter.setFacingVelocity(true);
    smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 6f, 0));
    smokeEmitter.getParticleInfluencer().setVelocityVariation(1);
    smokeEmitter.setStartSize(5f);
    smokeEmitter.setEndSize(30f);
    smokeEmitter.setParticlesPerSec(0);
    smokeEmitter.setLocalTranslation(pos);
  }
  private void initShockwave() {
    shockwaveEmitter = new ParticleEmitter("Shockwave", ParticleMesh.Type.Triangle, 2);
    shockwaveEmitter.setLocalTranslation(0, 15, 0);
    Material shockwaveMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    shockwaveMat.setTexture("Texture", assetManager.loadTexture("Effects/shockwave.png"));
    shockwaveEmitter.setImagesX(1);
    shockwaveEmitter.setImagesY(1);
    shockwaveEmitter.setMaterial(shockwaveMat);
    explosionEffect.attachChild(shockwaveEmitter);

    shockwaveEmitter.setFaceNormal(Vector3f.UNIT_Y);
    shockwaveEmitter.setStartColor(new ColorRGBA(.68f, 0.77f, 0.61f, 1f));
    shockwaveEmitter.setEndColor(new ColorRGBA(.68f, 0.77f, 0.61f, 0f));
    shockwaveEmitter.setStartSize(5f);
    shockwaveEmitter.setEndSize(20f);
    shockwaveEmitter.setGravity(0, 0, 0);
    shockwaveEmitter.setLowLife(1f);
    shockwaveEmitter.setHighLife(1f);
    shockwaveEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
    shockwaveEmitter.getParticleInfluencer().setVelocityVariation(0f);
    shockwaveEmitter.setParticlesPerSec(0);
    shockwaveEmitter.setLocalTranslation(pos);
  }
  private void initBurst() {
    burstEmitter = new ParticleEmitter("Flash", ParticleMesh.Type.Triangle, 5);
    Material burstMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    burstMat.setTexture("Texture", assetManager.loadTexture("Effects/flash.png"));
    burstEmitter.setMaterial(burstMat);
    burstEmitter.setImagesX(2);
    burstEmitter.setImagesY(2);
    burstEmitter.setSelectRandomImage(true);
    burstEmitter.setRandomAngle(true);
    explosionNode.attachChild(burstEmitter);

    burstEmitter.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1f));
    burstEmitter.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, .25f));
    burstEmitter.setStartSize(2f);
    burstEmitter.setEndSize(50.0f);
    burstEmitter.setGravity(0, 0, 0);
    burstEmitter.setLowLife(.75f);
    burstEmitter.setHighLife(.75f);
    burstEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2f, 0));
    burstEmitter.getParticleInfluencer().setVelocityVariation(1);
    burstEmitter.setShape(new EmitterSphereShape(Vector3f.ZERO, .5f));
    burstEmitter.setParticlesPerSec(0);
    burstEmitter.setLocalTranslation(pos);
  }
Ejemplo n.º 13
0
  /** Konstruktor překážky typu elektřina. */
  public FlashObstacle(AssetManager am) {
    super(am, ObstacleType.FLASH);

    /** Uses Texture from jme3-test-data library! */
    ParticleEmitter flash = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 24);
    Material mat_red = new Material(am, "Common/MatDefs/Misc/Particle.j3md");
    mat_red.setTexture("Texture", am.loadTexture("Effects/Explosion/flash.png"));
    flash.setMaterial(mat_red);
    flash.setSelectRandomImage(true);
    flash.setImagesX(2);
    flash.setImagesY(2);
    flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
    flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f));
    flash.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 5, 0));
    flash.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.05f));
    flash.setStartSize(0.1f);
    flash.setEndSize(3.0f);
    flash.setGravity(0f, 0f, 0f);
    flash.setLowLife(0.2f);
    flash.setHighLife(0.2f);
    flash.getParticleInfluencer().setVelocityVariation(1.0f);
    flash.setLocalTranslation(new Vector3f(0.0f, 1.5f, 0.0f));
    this.attachChild(flash);
  }
  private void initFire() {
    fireEmitter = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 100);
    Material fireMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    fireMat.setTexture("Texture", assetManager.loadTexture("Effects/flame.png"));
    fireEmitter.setMaterial(fireMat);
    fireEmitter.setImagesX(2);
    fireEmitter.setImagesY(2);
    fireEmitter.setRandomAngle(true);
    fireEmitter.setSelectRandomImage(true);
    fireEmitter.setShape(new EmitterSphereShape(Vector3f.ZERO, 2f));
    explosionNode.attachChild(fireEmitter);

    fireEmitter.setStartColor(new ColorRGBA(1f, 1f, .5f, 1f));
    fireEmitter.setEndColor(new ColorRGBA(1f, 0f, 0f, 0f));
    fireEmitter.setGravity(0, -.5f, 0);
    fireEmitter.setStartSize(8f);
    fireEmitter.setEndSize(0.02f);
    fireEmitter.setLowLife(.5f);
    fireEmitter.setHighLife(2f);
    fireEmitter.getParticleInfluencer().setVelocityVariation(0.3f);
    fireEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3f, 0));
    fireEmitter.setParticlesPerSec(0);
    fireEmitter.setLocalTranslation(pos);
  }
  private void initDebris() {
    debrisEmitter = new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10);
    Material debrisMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    debrisMat.setTexture("Texture", assetManager.loadTexture("Effects/debris.png"));
    debrisEmitter.setMaterial(debrisMat);
    debrisEmitter.setImagesX(3);
    debrisEmitter.setImagesY(3);
    debrisEmitter.setSelectRandomImage(true);
    debrisEmitter.setRandomAngle(true);
    explosionNode.attachChild(debrisEmitter);

    debrisEmitter.setRotateSpeed(FastMath.TWO_PI * 2);
    debrisEmitter.setStartColor(new ColorRGBA(0.4f, 0.4f, 0.4f, 1.0f));
    debrisEmitter.setEndColor(new ColorRGBA(0.4f, 0.4f, 0.4f, 1.0f));
    debrisEmitter.setStartSize(.3f);
    debrisEmitter.setEndSize(2f);
    debrisEmitter.setGravity(0, 10f, 0);
    debrisEmitter.setLowLife(2.7f);
    debrisEmitter.setHighLife(3.1f);
    debrisEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 45, 0));
    debrisEmitter.getParticleInfluencer().setVelocityVariation(.60f);
    debrisEmitter.setParticlesPerSec(0);
    debrisEmitter.setLocalTranslation(pos);
  }
Ejemplo n.º 16
0
  private Texture parseTextureType(final VarType type, final String value) {
    final List<String> textureValues = tokenizeTextureValue(value);
    final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);

    TextureKey textureKey = null;

    // If there is only one token on the value, it must be the path to the texture.
    if (textureValues.size() == 1) {
      textureKey = new TextureKey(textureValues.get(0), false);
    } else {
      String texturePath = value.trim();

      // If there are no valid "new" texture options specified but the path is split into several
      // parts, lets parse the old way.
      if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
        boolean flipY = false;

        if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
          texturePath = texturePath.substring(12).trim();
          flipY = true;
        } else if (texturePath.startsWith("Flip ")) {
          texturePath = texturePath.substring(5).trim();
          flipY = true;
        } else if (texturePath.startsWith("Repeat ")) {
          texturePath = texturePath.substring(7).trim();
        }

        // Support path starting with quotes (double and single)
        if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
          texturePath = texturePath.substring(1);
        }

        // Support path ending with quotes (double and single)
        if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
          texturePath = texturePath.substring(0, texturePath.length() - 1);
        }

        textureKey = new TextureKey(texturePath, flipY);
      }

      if (textureKey == null) {
        textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
      }

      // Apply texture options to the texture key
      if (!textureOptionValues.isEmpty()) {
        for (final TextureOptionValue textureOptionValue : textureOptionValues) {
          textureOptionValue.applyToTextureKey(textureKey);
        }
      }
    }

    switch (type) {
      case Texture3D:
        textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
        break;
      case TextureArray:
        textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
        break;
      case TextureCubeMap:
        textureKey.setTextureTypeHint(Texture.Type.CubeMap);
        break;
    }

    textureKey.setGenerateMips(true);

    Texture texture;

    try {
      texture = assetManager.loadTexture(textureKey);
    } catch (AssetNotFoundException ex) {
      logger.log(
          Level.WARNING, "Cannot locate {0} for material {1}", new Object[] {textureKey, key});
      texture = null;
    }

    if (texture == null) {
      texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
      texture.setKey(textureKey);
      texture.setName(textureKey.getName());
    }

    // Apply texture options to the texture
    if (!textureOptionValues.isEmpty()) {
      for (final TextureOptionValue textureOptionValue : textureOptionValues) {
        textureOptionValue.applyToTexture(texture);
      }
    }

    return texture;
  }
  public static void main(String[] args) {
    AssetManager assetManager =
        JmeSystem.newAssetManager(
            TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));

    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);

    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);

    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);

    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);

    // Comparing same textures
    TextureKey originalKey =
        (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);

    // Texture keys from the original and the loaded texture
    // must be identical, otherwise the resultant textures not identical
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)) {
      System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }

    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);

    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);

    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);

    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);

    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
  }
Ejemplo n.º 18
0
 /**
  * Set the image to put on the picture.
  *
  * @param assetManager The {@link AssetManager} to use to load the image.
  * @param imgName The image name.
  * @param useAlpha If true, the picture will appear transparent and allow objects behind it to
  *     appear through. If false, the transparent portions will be the image's color at that pixel.
  */
 public void setImage(AssetManager assetManager, String imgName, boolean useAlpha) {
   TextureKey key = new TextureKey(imgName, true);
   Texture2D tex = (Texture2D) assetManager.loadTexture(key);
   setTexture(assetManager, tex, useAlpha);
 }