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 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));
    }
  }
Exemple #3
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;
  }
 public static void main(String[] args) {
   AssetManager assetManager = JmeSystem.newAssetManager();
   assetManager.registerLocator("/", ClasspathLocator.class);
   assetManager.registerLoader(TextLoader.class, "fnt");
   System.out.println(assetManager.loadAsset("Interface/Fonts/Console.fnt"));
 }