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);
 }
예제 #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);
    }
  }
  /**
   * find the definiton from this statement (loads it if necessary)
   *
   * @param statement the statement being read
   * @return the definition
   * @throws IOException
   */
  public ShaderNodeDefinition findDefinition(Statement statement) throws IOException {
    String defLine[] = statement.getLine().split(":");
    String defName = defLine[1].trim();

    ShaderNodeDefinition def = getNodeDefinitions().get(defName);
    if (def == null) {
      if (defLine.length == 3) {
        List<ShaderNodeDefinition> defs = null;
        try {
          defs = assetManager.loadAsset(new ShaderNodeDefinitionKey(defLine[2].trim()));
        } catch (AssetNotFoundException e) {
          throw new MatParseException("Couldn't find " + defLine[2].trim(), statement, e);
        }

        for (ShaderNodeDefinition definition : defs) {
          definition.setPath(defLine[2].trim());
          if (defName.equals(definition.getName())) {
            def = definition;
          }
          if (!(getNodeDefinitions().containsKey(definition.getName()))) {
            getNodeDefinitions().put(definition.getName(), definition);
          }
        }
      }
      if (def == null) {
        throw new MatParseException(
            defName + " is not a declared as Shader Node Definition", statement);
      }
    }
    return def;
  }
  public void showCar() {
    for (int i = 0; i < 4; i++) {
      cars[i] = factory.getCar(car_names[i], assetManager);
      car_con[i] = cars[i].getControl(VehicleControl.class);
    }
    Camera camera = cam.clone();

    camera.setViewPort(.25f, .9f, .1f, .75f);
    carView = this.app.getRenderManager().createPostView("carview", camera);

    space.add(car_con[index]);
    dl = new DirectionalLight();
    localRootNode.addLight(dl);
    ai = new AmbientLight();
    localRootNode.addLight(ai);
    car_con[index].setPhysicsLocation(new Vector3f(0, 1, 0));
    localRootNode.attachChild(cars[index]);
    floor = assetManager.loadModel("Models/garage/garage.mesh.j3o");
    control = new RigidBodyControl(0);
    floor.addControl(control);
    control.setPhysicsLocation(Vector3f.ZERO);
    space.add(control);
    localRootNode.attachChild(floor);

    camera.setLocation(car_con[index].getPhysicsLocation().add(new Vector3f(3, 1f, 0)));
    camera.lookAt(car_con[index].getPhysicsLocation().add(new Vector3f(0, -1, 0)), Vector3f.UNIT_Y);
    dl.setDirection(camera.getDirection());

    carView.attachScene(localRootNode);
  }
예제 #5
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;
 }
 /**
  * gets an effect from the list (is exists) or loads a new one
  *
  * @param name
  * @return
  */
 private Node getEffect(String name) {
   if (emitters.get(name) == null) {
     emitters.put(name, new LinkedList<Node>());
   }
   Node emit = emitters.get(name).poll();
   if (emit == null) {
     emit = (Node) assetManager.loadModel(name);
   }
   return emit;
 }
  public Characters(SimpleApplication app) {
    assetManager = app.getAssetManager();

    characters =
        new Object[][] {
          {"Tahu", assetManager.loadModel("Models/Characters/Tahu/Tahu.mesh.j3o"), 90, 30, 30},
          {2, 3, 4},
          {4, 5, 2}
        };
  }
예제 #8
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!");
  }
예제 #9
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);
 }
예제 #10
0
 public void createMonster() {
   Monster monster = new Monster();
   monster.health = 20;
   monster.attackDelay = 0;
   monster.monsterControl = new BetterCharacterControl(1f, 5f, 1f);
   monster.Model = (Node) assetManager.loadModel("Models/RealMonster/RealMonster.j3o");
   monster.Model.setLocalScale(.8f);
   monster.Model.addControl(monster.monsterControl);
   monster.monsterControl.setGravity(new Vector3f(0f, -9.81f, 0f));
   monster.anim = new AnimationManager();
   monster.anim.animationInit(monster.Model);
   physics.getPhysicsSpace().add(monster.monsterControl);
   monster.attachChild(monster.Model);
   monsterNode.attachChild(monster);
   monster.monsterSetLocation(monster);
 }
예제 #11
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;
 }
예제 #12
0
  public void initMachineScreenText() {

    Box box2 = new Box(6, 0.5f, 0.2f);
    Geometry red = new Geometry("Box", box2);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.Black);
    red.setName("MachineScreen");
    red.setMaterial(mat2);
    red.setLocalScale(0.5f);
    red.setLocalTranslation(-0.0f, 2.0f, -4.7f);
    rootNode.attachChild(red);

    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText inHand = new BitmapText(guiFont, false);
    inHand.setSize(guiFont.getCharSet().getRenderedSize());
    inHand.setText("Welcome");
    inHand.setName("MachineScreenText");
    inHand.setLocalScale(0.01f);
    inHand.setLocalTranslation(-2.8f, 2.0f, -4.5f);
    rootNode.attachChild(inHand);
  }
  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);
  }
  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);
  }
예제 #15
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;
  }
  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 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 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);
  }
  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 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);
  }
예제 #21
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);
  }
예제 #22
0
 /**
  * Constructor
  *
  * @param assetManager to load models
  */
 public BargeShip(AssetManager assetManager) {
   bargeship = assetManager.loadModel("Models/Ship/BargeShip/BargeBoot.j3o");
   bargeship.setCullHint(cullHint.Dynamic);
   bargeship.scale(3);
   attachChild(bargeship);
 }
예제 #23
0
 public static Material getMaterial(String materialPath) {
   if (materials.get(materialPath) == null)
     materials.put(materialPath, am.loadMaterial(materialPath));
   return materials.get(materialPath);
 }
예제 #24
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 void prepareManager(AssetManager manager) {
   manager.registerLoader(com.jme3.scene.plugins.blender.BlenderModelLoader.class, "blend");
 }
  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);
  }
예제 #27
0
  /**
   * Check that we have all we need to run this app
   *
   * @param app the app (we need asset managers etc.)
   * @return true if the app is ok for running!
   * @throws InterruptedException lots of threads waiting
   */
  private static boolean checkSetup(final Main app) throws InterruptedException {

    boolean saveSetup = false;

    // First and foremost, the folder
    if (!checkDkFolder(dkIIFolder)) {
      logger.info("Dungeon Keeper II folder not found or valid! Prompting user!");
      saveSetup = true;

      // Let the user select
      setLookNFeel();
      DKFolderSelector frame =
          new DKFolderSelector() {
            @Override
            protected void continueOk(String path) {
              if (!path.endsWith(File.separator)) {
                dkIIFolder = path.concat(File.separator);
              }
              app.getSettings().putString(DKII_FOLDER_KEY, dkIIFolder);
              folderOk = true;
            }
          };
      openFrameAndWait(frame);
    } else {
      folderOk = true;
    }

    // If the folder is ok, check the conversion
    if (folderOk && (AssetsConverter.conversionNeeded(app.getSettings()))) {
      logger.info("Need to convert the assets!");
      saveSetup = true;

      // Convert
      setLookNFeel();
      AssetManager assetManager =
          JmeSystem.newAssetManager(
              Thread.currentThread()
                  .getContextClassLoader()
                  .getResource(
                      "com/jme3/asset/Desktop.cfg")); // Get temporary asset manager instance since
      // we not yet have one ourselves
      assetManager.registerLocator(AssetsConverter.getAssetsFolder(), FileLocator.class);
      DKConverter frame =
          new DKConverter(dkIIFolder, assetManager) {
            @Override
            protected void continueOk() {
              AssetsConverter.setConversionSettings(app.getSettings());
              conversionOk = true;
            }
          };
      openFrameAndWait(frame);
    } else if (folderOk) {
      conversionOk = true;
    }

    // If everything is ok, we might need to save the setup
    boolean result = (folderOk && conversionOk);
    if (result && saveSetup) {
      try {
        app.getSettings().save(new FileOutputStream(new File(SETTINGS_FILE)));
      } catch (IOException ex) {
        Logger.getLogger(Main.class.getName())
            .log(Level.WARNING, "Settings file failed to save!", ex);
      }
    }

    return result;
  }
예제 #28
0
  private static void initBaseMaterials() {
    ColorRGBA lotColorBase = new ColorRGBA(200f / 255f, 200f / 255f, 200f / 255f, 255f / 255f);
    ColorRGBA concreteColor = new ColorRGBA(90f / 255f, 100f / 255f, 255f / 255f, 255f / 255f);
    ColorRGBA redConcreteColor = ColorRGBA.Red;
    ColorRGBA blueConcreteColor = ColorRGBA.Blue;
    ColorRGBA yellowConcreteColor = ColorRGBA.Yellow;
    ColorRGBA cyanConcreteColor = new ColorRGBA(0, 1, 1, 0.4f);
    ColorRGBA blackConcreteColor = ColorRGBA.Black;
    ColorRGBA greenConcreteColor = ColorRGBA.Green;
    ColorRGBA floorColor = ColorRGBA.Gray;
    ColorRGBA windowsColor = ColorRGBA.White;
    ColorRGBA itemColor = ColorRGBA.LightGray;
    ColorRGBA roadsColor = ColorRGBA.LightGray;
    ColorRGBA terrainColor = new ColorRGBA(0f / 255f, 50f / 255f, 14f / 255f, 255f / 255f);

    am.registerLocator("assets/", FileLocator.class.getName());

    contourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    contourMaterial.setColor("Color", blackConcreteColor);

    blockContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    blockContourMaterial.setColor("Color", redConcreteColor);

    lotContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotContourMaterial.setColor("Color", blueConcreteColor);

    lotMaterial1 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotMaterial1.setColor("Color", lotColorBase);

    lotMaterial2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotMaterial2.setColor("Color", lotColorBase);

    lotMaterial3 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    lotMaterial3.setColor("Color", lotColorBase);

    // debug material
    debugMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterial.setColor("Color", redConcreteColor);
    // debug texture material
    // debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
    // debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    // debugTextureMaterial.setTexture("DiffuseMap",
    // assetManager.loadTexture("Textures/UVTest.jpg"));
    // debugTextureMaterial.setFloat("Shininess", 128f); // [0,128]

    // Red Material
    redMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    redMaterial.setColor("Color", redConcreteColor);
    redMaterial.setColor("GlowColor", redConcreteColor);

    // Concrete Material
    yellowMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    yellowMaterial.setColor("Color", yellowConcreteColor);

    // Concrete Material
    cyanMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    cyanMaterial.setColor("Color", cyanConcreteColor);
    cyanMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    // Concrete Material
    blackMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    blackMaterial.setColor("Color", blackConcreteColor);

    // Concrete Material
    greenMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
    greenMaterial.setColor("Color", greenConcreteColor);
    greenMaterial.setColor("GlowColor", greenConcreteColor);

    // Item Material
    itemMaterial = new Material(am, "Common/MatDefs/Light/Lighting.j3md");
    itemMaterial.setColor("Diffuse", itemColor);
    itemMaterial.setBoolean("UseMaterialColors", true);

    // gradient blue
    for (int i = 0; i < 4; i++) {
      gradientMaterial.add(new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"));
      gradientMaterial
          .get(i)
          .setColor("Color", new ColorRGBA(i * 30 / 255f, i * 30 / 255f, i * 85 / 255f, 1));
    }
  }
예제 #29
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);
 }
예제 #30
0
  private void loadFromRoot(List<Statement> roots) throws IOException {
    if (roots.size() == 2) {
      Statement exception = roots.get(0);
      String line = exception.getLine();
      if (line.startsWith("Exception")) {
        throw new AssetLoadException(line.substring("Exception ".length()));
      } else {
        throw new IOException("In multiroot material, expected first statement to be 'Exception'");
      }
    } else if (roots.size() != 1) {
      throw new IOException("Too many roots in J3M/J3MD file");
    }

    boolean extending = false;
    Statement materialStat = roots.get(0);
    String materialName = materialStat.getLine();
    if (materialName.startsWith("MaterialDef")) {
      materialName = materialName.substring("MaterialDef ".length()).trim();
      extending = false;
    } else if (materialName.startsWith("Material")) {
      materialName = materialName.substring("Material ".length()).trim();
      extending = true;
    } else {
      throw new IOException("Specified file is not a Material file");
    }

    String[] split = materialName.split(":", 2);

    if (materialName.equals("")) {
      throw new MatParseException("Material name cannot be empty", materialStat);
    }

    if (split.length == 2) {
      if (!extending) {
        throw new MatParseException("Must use 'Material' when extending.", materialStat);
      }

      String extendedMat = split[1].trim();

      MaterialDef def = (MaterialDef) assetManager.loadAsset(new AssetKey(extendedMat));
      if (def == null) {
        throw new MatParseException(
            "Extended material " + extendedMat + " cannot be found.", materialStat);
      }

      material = new Material(def);
      material.setKey(key);
      material.setName(split[0].trim());
      //            material.setAssetName(fileName);
    } else if (split.length == 1) {
      if (extending) {
        throw new MatParseException("Expected ':', got '{'", materialStat);
      }
      materialDef = new MaterialDef(assetManager, materialName);
      // NOTE: pass file name for defs so they can be loaded later
      materialDef.setAssetName(key.getName());
    } else {
      throw new MatParseException("Cannot use colon in material name/path", materialStat);
    }

    for (Statement statement : materialStat.getContents()) {
      split = statement.getLine().split("[ \\{]");
      String statType = split[0];
      if (extending) {
        if (statType.equals("MaterialParameters")) {
          readExtendingMaterialParams(statement.getContents());
        } else if (statType.equals("AdditionalRenderState")) {
          readAdditionalRenderState(statement.getContents());
        } else if (statType.equals("Transparent")) {
          readTransparentStatement(statement.getLine());
        }
      } else {
        if (statType.equals("Technique")) {
          readTechnique(statement);
        } else if (statType.equals("MaterialParameters")) {
          readMaterialParams(statement.getContents());
        } else {
          throw new MatParseException(
              "Expected material statement, got '" + statType + "'", statement);
        }
      }
    }
  }