Java 类com.badlogic.gdx.graphics.g3d.Material 实例源码

项目:ZombieInvadersVR    文件:GameObject.java   
public GameObject(ScreenBase context, Model model, BoundingBox bounds) {
super(model);
this.context = context;
this.customBounds = bounds;

      this.bounds = this.customBounds != null ? this.customBounds : new BoundingBox();
      this.center = new Vector3();
      this.enabled = true;
      updateBox();

      this.animations = new AnimationController(this);
      this.blending = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

      for(Material item : materials){
        item.set(new DepthTestAttribute(GL20.GL_LEQUAL, 0.01f, 25f, true));
    item.set(FloatAttribute.createAlphaTest(0.01f));
        item.set(blending);
      }
  }
项目:Planetbase    文件:StrategyGame.java   
@Deprecated //Only for creating the first one
private void createEntity(float f, float g, float h) {
    Vector3 position=new Vector3(f,g,h);
    List<EntityStatic> collidingEntities=space.getWithin(position, 0.03);

    if(collidingEntities.size() == 0) {
        EntityStatic entity=new EntityStatic(new ModelInstance(
                Assets.modelBuilder.createBox(0.03f, 0.03f, 0.06f, 
                        new Material(StrategyGame.blueAttr), 
                        Usage.Normal | Usage.Position)),
                position);

        space.addEntity(entity);
    } else {
        for(EntityStatic e:collidingEntities){
            e.damage(2);
        }
    }
}
项目:nhglib    文件:MainDef.java   
@Override
public void create() {
    super.create();

    geometryPass = new ShaderProgram(
            Gdx.files.internal("shaders/g_buffer.vert"),
            Gdx.files.internal("shaders/g_buffer.frag"));

    lightingPass = new ShaderProgram(
            Gdx.files.internal("shaders/deferred_shader.vert"),
            Gdx.files.internal("shaders/deferred_shader.frag"));

    ModelBuilder mb = new ModelBuilder();
    Model cube = mb.createBox(1, 1, 1, new Material(),
            VertexAttributes.Usage.Position |
                    VertexAttributes.Usage.Normal |
                    VertexAttributes.Usage.TextureCoordinates);
    cubeMesh = cube.meshes.first();
}
项目:Argent    文件:MaterialPanel.java   
@Override
    protected AbstractPanel select(T obj) {
        super.select(obj);
        if(obj == null) {
            matList.clearItems();
            selectMtl(null);
            return this;
        }
        ModelInstance inst = gameWorld.renderer().getRenderable(obj);
        matList.clearItems();
        inst.nodes.forEach(n -> n.parts.forEach(p -> {
            ArgentList.ArgentListElement<Material> e = new ArgentList.ArgentListElement<>(p.material, this::selectMtl);
            e.getString = () -> String.format("[%s] %s", n.id, e.obj.id);
            matList.addItem(e);
        }));
//        inst.materials.forEach(m -> {
//            ArgentList.ArgentListElement<Material> e = new ArgentList.ArgentListElement<>(m, this::selectMtl);
//            e.getString = () -> e.obj.id;
//            matList.addItem(e);
//        });

        selectMtl(null);
        return this;
    }
项目:Argent    文件:MaterialPanel.java   
private void selectMtl(Material mtl) {
        configTree.clearChildren();
        selectedMtl = mtl;
        if(mtl == null) return;
        MaterialWrapper wrapper = new MaterialWrapper(mtl);
        List<ConfigurableAttribute<?>> attrs = wrapper.getConfigAttrs();
        builder.compileSet(configTree, attrs);
        configTree.getRootNodes().forEach(node -> node.setExpanded(true));
//        attrs.forEach(ca -> {
//            System.out.println(ca.displayName());
//            Object compObj = builder.buildComponent(ca);
//            if (compObj instanceof Actor) {
//                float compWidth = getWidth()-192;
//                configTable.add(new Label(ca.displayName(), skin)).width(192);
//                configTable.add((Actor) compObj).width(compWidth-10);
//                configTable.row();
//            }
//        });
    }
项目:eamaster    文件:SimulationRunner.java   
public SimulationRunner() {
    logger.info("Loading models");
    ModelBuilder builder = new ModelBuilder();
    models.put("box", builder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(new Color(0.8f, 0f, 0f, 0f))),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal));

    G3dModelLoader loader = new G3dModelLoader(new JsonReader());
    models.put("hub", loader.loadModel(Gdx.files.internal("data/hubreal.g3dj")));
    models.put("rim", loader.loadModel(Gdx.files.internal("data/rimreal.g3dj")));
    models.put("spoke", loader.loadModel(Gdx.files.internal("data/spoke.g3dj")));


    Bullet.init();
    logger.info("Initialized Bullet");
}
项目:Mundus    文件:Terrain.java   
private Terrain(int vertexResolution) {
    this.transform = new Matrix4();
    this.attribs = MeshBuilder.createAttributes(VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal
            | VertexAttributes.Usage.TextureCoordinates);
    this.posPos = attribs.getOffset(VertexAttributes.Usage.Position, -1);
    this.norPos = attribs.getOffset(VertexAttributes.Usage.Normal, -1);
    this.uvPos = attribs.getOffset(VertexAttributes.Usage.TextureCoordinates, -1);
    this.stride = attribs.vertexSize / 4;

    this.vertexResolution = vertexResolution;
    this.heightData = new float[vertexResolution * vertexResolution];

    this.terrainTexture = new TerrainTexture();
    this.terrainTexture.setTerrain(this);
    material = new Material();
    material.set(new TerrainTextureAttribute(TerrainTextureAttribute.ATTRIBUTE_SPLAT0, terrainTexture));
}
项目:Mundus    文件:UsefulMeshs.java   
public static Model createAxes() {
    final float GRID_MIN = -10f;
    final float GRID_MAX = 10f;
    final float GRID_STEP = 1f;
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material());
    builder.setColor(Color.LIGHT_GRAY);
    for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
        builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
        builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 100, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 100, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 100);
    return modelBuilder.end();
}
项目:Mundus    文件:RotateTool.java   
public RotateHandle(int id, Color color) {
    super(id);
    model = UsefulMeshs.torus(new Material(ColorAttribute.createDiffuse(color)), 20, 1f, 50, 50);
    modelInstance = new ModelInstance(model);
    modelInstance.materials.first().set(getIdAttribute());
    switch (id) {
    case X_HANDLE_ID:
        this.getRotationEuler().y = 90;
        this.getScale().x = 0.9f;
        this.getScale().y = 0.9f;
        this.getScale().z = 0.9f;
        break;
    case Y_HANDLE_ID:
        this.getRotationEuler().x = 90;
        break;
    case Z_HANDLE_ID:
        this.getRotationEuler().z = 90;
        this.getScale().x = 1.1f;
        this.getScale().y = 1.1f;
        this.getScale().z = 1.1f;
        break;
    }
    // mi.transform.translate(0, 100, 0);
}
项目:Mundus    文件:ScaleTool.java   
public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, handlePicker, batch, history);

    this.shapeRenderer = shapeRenderer;

    ModelBuilder modelBuilder = new ModelBuilder();
    Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)),
            Vector3.Zero, new Vector3(15, 0, 0));
    Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            Vector3.Zero, new Vector3(0, 15, 0));
    Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            Vector3.Zero, new Vector3(0, 0, 15));
    Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3,
            new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

    xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
    yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
    zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
    xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);

    handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle };
}
项目:GdxDemo3D    文件:ModelFactory.java   
public static Model buildPlaneModel(final float width,
                                    final float height, final Material material, final float u1,
                                    final float v1, final float u2, final float v2) {

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder bPartBuilder = modelBuilder.part("rect", GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position
                    | VertexAttributes.Usage.Normal
                    | VertexAttributes.Usage.TextureCoordinates, material);
    bPartBuilder.setUVRange(u1, v1, u2, v2);
    bPartBuilder.rect(-(width * 0.5f), -(height * 0.5f), 0, (width * 0.5f),
            -(height * 0.5f), 0, (width * 0.5f), (height * 0.5f), 0,
            -(width * 0.5f), (height * 0.5f), 0, 0, 0, -1);

    return (modelBuilder.end());
}
项目:Alien-Ark    文件:MaterialInterpreter.java   
public MaterialInterpreter() {

        waterColor = new Color(0.13f, 0.05f, 0.8f, 1);
        waterMaterial = new Material(
                ColorAttribute.createDiffuse(waterColor),
                ColorAttribute.createSpecular(1, 1, 1, 1),
                FloatAttribute.createShininess(8f));

        sandColor = new Color(0.9f, 0.733f, 0.58f, 1);
        sandMaterial = new Material(ColorAttribute.createDiffuse(sandColor),
                ColorAttribute.createSpecular(1, 1, 1, 1),
                FloatAttribute.createShininess(8f));

        grassColor = new Color(0f, 1f, 0f, 1f);
        grassMaterial = new Material(ColorAttribute.createDiffuse(grassColor),
                ColorAttribute.createSpecular(1, 1, 1, 1),
                FloatAttribute.createShininess(8f));

    }
项目:Alien-Ark    文件:ControllerPlanet.java   
public static Model createInfiniteWaterPart(TypeInterpreter interpreter, int landscapeIndex, PlanetConfig planetConfig) {
    ModelBuilder modelBuilder = new ModelBuilder();
    MeshBuilder builder = new MeshBuilder();
    float waterHeight = interpreter.it.get(landscapeIndex).endValue;
    builder.begin(PlanetPart.VERTEX_ATTRIBUTES, GL20.GL_TRIANGLES);
    infiniteWaterHeight = waterHeight * planetConfig.landscapeHeight - 1;
    Vector3 corner01 = new Vector3(-INFINITE_WATER_SIZE, -INFINITE_WATER_SIZE, infiniteWaterHeight);
    Vector3 corner02 = new Vector3(INFINITE_WATER_SIZE, -INFINITE_WATER_SIZE, infiniteWaterHeight);
    Vector3 corner03 = new Vector3(INFINITE_WATER_SIZE, INFINITE_WATER_SIZE, infiniteWaterHeight);
    Vector3 corner04 = new Vector3(-INFINITE_WATER_SIZE, INFINITE_WATER_SIZE, infiniteWaterHeight);
    builder.rect(corner01, corner02, corner03, corner04, new Vector3(0, 0, 1));
    Material waterMaterial = planetConfig.layerConfigs.get(landscapeIndex).material;
    Mesh mesh = builder.end();
    modelBuilder.begin();
    modelBuilder.part(PlanetPart.LANDSCAPE_PART_NAME + landscapeIndex, mesh, GL20.GL_TRIANGLES, waterMaterial);
    return modelBuilder.end();
}
项目:Alien-Ark    文件:PlanetPart.java   
/**
 * Creates a water plane.
 * @param chunk The chunk.
 */
private void createWaterPart(Chunk chunk, int landscapeIndex) {
    MeshBuilder builder = meshBuilders.get(landscapeIndex);
    float WATER_HEIGHT = interpreter.it.get(landscapeIndex).endValue;
    builder.begin(VERTEX_ATTRIBUTES, GL20.GL_TRIANGLES);
    float z = WATER_HEIGHT * planetConfig.landscapeHeight;
    float width = chunk.getWidth() * tileSize;
    float height = chunk.getHeight() * tileSize;

    Vector3 corner01 = new Vector3(0f, 0f, z);
    Vector3 corner02 = new Vector3(width, 0f, z);
    Vector3 corner03 = new Vector3(width, height, z);
    Vector3 corner04 = new Vector3(0f, height, z);

    builder.rect(corner01, corner02, corner03, corner04, new Vector3(0, 0, 1));
    Material waterMaterial = planetConfig.layerConfigs.get(landscapeIndex).material;
    Mesh mesh = builder.end();
    modelBuilder.node().id = LANDSCAPE_NODE_NAME + landscapeIndex;
    modelBuilder.part(LANDSCAPE_PART_NAME + landscapeIndex, mesh, GL20.GL_TRIANGLES, waterMaterial);
}
项目:ForgE    文件:TerrainBuilder.java   
private VoxelChunkRenderable buildFaceForChunkWithAssembler(Chunk chunk, VoxelsAssembler assembler, boolean haveTransparency) {
  if (!assembler.isEmpty()) {
    VoxelChunkRenderable renderable   = new VoxelChunkRenderable();
    renderable.primitiveType          = GL30.GL_TRIANGLES;

    if (ForgE.config.getBool(Config.Key.GenerateWireframe))
      renderable.wireframe           = assembler.wireframe();
    renderable.triangleCount         = assembler.getTriangleCount();
    renderable.meshFactory           = assembler.meshFactory(MeshVertexInfo.voxelTypes());

    renderable.worldTransform.idt();
    renderable.material = new Material(new SolidTerrainAttribute());
    if (haveTransparency) {
      renderable.material.set(new BlendingAttribute(true,1f));
    }

    chunk.addFace(renderable);
    return renderable;
  } else {
    return null;
  }
}
项目:gdx-proto    文件:ModelManager.java   
/** players are represented by cubes, with another cube marking the direction it is facing */
public void createPlayerModel() {
    ModelBuilder mb = new ModelBuilder();
    ModelBuilder mb2 = new ModelBuilder();
    long attr = Usage.Position | Usage.Normal;
    float r = 0.5f;
    float g = 1f;
    float b = 0.75f;
    Material material = new Material(ColorAttribute.createDiffuse(new Color(r, g, b, 1f)));
    Material faceMaterial = new Material(ColorAttribute.createDiffuse(Color.BLUE));
    float w = 1f;
    float d = w;
    float h = 2f;
    mb.begin();
    //playerModel = mb.createBox(w, h, d, material, attr);
    Node node = mb.node("box", mb2.createBox(w, h, d, material, attr));
    // the face is just a box to show which direction the player is facing
    Node faceNode = mb.node("face", mb2.createBox(w/2, h/2, d/2, faceMaterial, attr));
    faceNode.translation.set(0f, 0f, d/2);
    playerModel = mb.end();
}
项目:amatsukaze    文件:Basic3DTest.java   
@Override
    public void create () {
        modelBatch = new ModelBatch(new DefaultShaderProvider());
// modelBatch = new ModelBatch();
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

        cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        cam.position.set(10f, 10f, 10f);
        cam.lookAt(0, 0, 0);
        cam.near = 0.1f;
        cam.far = 300f;
        cam.update();

        ModelBuilder modelBuilder = new ModelBuilder();
        model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position
            | Usage.Normal);
        instance = new ModelInstance(model);

// model = new G3dModelLoader(new UBJsonReader()).loadModel(Gdx.files.internal("data/g3d/knight.g3db"));
// instance = new ModelInstance(model);

        Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
    }
项目:bladecoder-adventure-engine    文件:Utils3D.java   
private static void createAxes() {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
    builder.setColor(Color.LIGHT_GRAY);
    for (float t = GRID_MIN; t <= GRID_MAX; t+=GRID_STEP) {
        builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
        builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 10, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 10, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 10);
    axesModel = modelBuilder.end();
    axesInstance = new ModelInstance(axesModel);
}
项目:libgdxcn    文件:ModelBuilder.java   
/** Convenience method to create a model which represents a grid of lines on the XZ plane. The resources the Material might
 * contain are not managed, use {@link Model#manageDisposable(Disposable)} to add those to the model.
 * @param xDivisions row count along x axis.
 * @param zDivisions row count along z axis.
 * @param xSize Length of a single row on x.
 * @param zSize Length of a single row on z. */
public Model createLineGrid (int xDivisions, int zDivisions, float xSize, float zSize, Material material, long attributes) {
    begin();
    MeshPartBuilder partBuilder = part("lines", GL20.GL_LINES, attributes, material);
    float xlength = xDivisions * xSize, zlength = zDivisions * zSize, hxlength = xlength / 2, hzlength = zlength / 2;
    float x1 = -hxlength, y1 = 0, z1 = hzlength, x2 = -hxlength, y2 = 0, z2 = -hzlength;
    for (int i = 0; i <= xDivisions; ++i) {
        partBuilder.line(x1, y1, z1, x2, y2, z2);
        x1 += xSize;
        x2 += xSize;
    }

    x1 = -hxlength;
    y1 = 0;
    z1 = -hzlength;
    x2 = hxlength;
    y2 = 0;
    z2 = -hzlength;
    for (int j = 0; j <= zDivisions; ++j) {
        partBuilder.line(x1, y1, z1, x2, y2, z2);
        z1 += zSize;
        z2 += zSize;
    }

    return end();
}
项目:amatsukaze    文件:BaseG3dTest.java   
private void createAxes () {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
    builder.setColor(Color.LIGHT_GRAY);
    for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
        builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
        builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 100, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 100, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 100);
    axesModel = modelBuilder.end();
    axesInstance = new ModelInstance(axesModel);
}
项目:libgdxcn    文件:ShaderTest.java   
@Override
public void create () {
    modelBatch = new ModelBatch(new BaseShaderProvider() {
        @Override
        protected Shader createShader (Renderable renderable) {
            return new TestShader();
        }
    });

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    Material material = new Material(new TestAttribute(1f));
    ModelBuilder builder = new ModelBuilder();
    model = builder.createCone(5, 5, 5, 20, material, Usage.Position);
    instance = new ModelInstance(model);
    testAttribute = (TestAttribute)instance.materials.get(0).get(TestAttribute.ID);
}
项目:libgdxcn    文件:FogTest.java   
@Override
public void create () {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(30f, 10f, 30f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 45f;
    cam.update();

    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position
        | Usage.Normal);
    instance = new ModelInstance(model);

    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
项目:libgdxcn    文件:CullTest.java   
@Override
public void create () {
    ModelBuilder builder = new ModelBuilder();
    sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)),
        Usage.Position | Usage.Normal);
    // cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()));

    cam.near = 1;
    cam.far = 200;

    Random rand = new Random();
    for (int i = 0; i < instances.length; i++) {
        pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100,
            rand.nextFloat() * -100 - 3);
        instances[i] = new ModelInstance(sphere, pos);
    }
    modelBatch = new ModelBatch();

    batch = new SpriteBatch();
    font = new BitmapFont();
    // Gdx.graphics.setVSync(true);
    // Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString());
}
项目:HelixEngine    文件:AreaDisplayable.java   
public AreaDisplayable(Model model) {
  instance = new ModelInstance(model);

  animationController = new AnimationController(instance);

  instance.transform.rotate(new Vector3(1, 0, 0), 90);

  for (Material material : instance.materials) {
    TextureAttribute ta
        = (TextureAttribute) material.get(TextureAttribute.Diffuse);

    ta.textureDescription.magFilter = Texture.TextureFilter.Nearest;
    ta.textureDescription.minFilter = Texture.TextureFilter.Nearest;

    material.set(ta);
    material.set(ColorAttribute.createDiffuse(Color.WHITE));

    BlendingAttribute ba = new BlendingAttribute(GL20.GL_SRC_ALPHA,
                                                 GL20.GL_ONE_MINUS_SRC_ALPHA);

    material.set(ba);
  }
}
项目:amatsukaze    文件:AxisModelGenerator.java   
public ModelInstance createAxes () {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
    builder.setColor(Color.LIGHT_GRAY);
    for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
        builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
        builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 100, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 100, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 100);
    Model axesModel = modelBuilder.end();
    ModelInstance axesInstance = new ModelInstance(axesModel);
    return axesInstance;
}
项目:GdxStudio    文件:Game3d.java   
public Game3d(){
   ship = Asset.loadModelObj("ship");//loads an obj model
   ship.scale(3f);
   skydome = Asset.loadModel("skydome"); //loads a g3db model
   builder = new ModelBuilder();
   builder.begin();
   MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | 
        Usage.TextureCoordinates | Usage.Normal, new Material());
   for (float x = -200f; x < 200f; x += 10f) {
       for (float z = -200f; z < 200f; z += 10f) {
           part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
       }
   }
   floor = new Actor3d(builder.end());
   floor.materials.get(0).set(TextureAttribute.createDiffuse(Asset.tex("concrete").getTexture()));
   knight = Asset.loadModel("knight");
   knight.setPosition(-20f, 18f, 0f);
   knight.setPitch(-90f);
   addActor3d(floor);
   addActor3d(skydome);
   addActor3d(ship);
   addActor3d(knight);
   stage3d.getCamera().position.set(knight.getX()+ 13f, knight.getY() + 24f, knight.getZ() + 45f);
   //Camera3d.followOffset(20f, 20f, -20f);
  // Camera3d.followActor3d(knight, false);
}
项目:gdx-vr    文件:SimpleRoom.java   
@Override
public void create() {
    assets = new AssetManager();
    String model = "Bambo_House.g3db";
    assets.load(model, Model.class);
    assets.finishLoading();
    modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f));

    DefaultShader.Config config = new Config();
    config.defaultCullFace = GL20.GL_NONE;
    ShaderProvider shaderProvider = new DefaultShaderProvider(config);
    modelBatch = new ModelBatch(shaderProvider);

    ModelBuilder builder = new ModelBuilder();
    float groundSize = 1000f;
    ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0,
            1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0));
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    VirtualReality.renderer.listeners.add(this);
    // VirtualReality.head.setCyclops(true);
}
项目:gdx-proto    文件:ModelManager.java   
public void createBillboardTest() {
    ModelBuilder mb = new ModelBuilder();
    mb.begin();

    long attr = Usage.TextureCoordinates | Usage.Position | Usage.Normal;
    TextureRegion region = Assets.getAtlas().findRegion("sprites/test-guy");
    Material mat = new Material(TextureAttribute.createDiffuse(region.getTexture()));
    boolean blended = true;
    float opacity = 1f;
    mat.set(new BlendingAttribute(blended, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity));
    MeshPartBuilder mpb = mb.part("rect", GL20.GL_TRIANGLES, attr, mat);
    mpb.setUVRange(region);
    // the coordinates are offset so that we can easily set the center position to align with the entity's body
    float sz = 2f; // size
    float b = -sz/2; // base
    float max = sz/2; // max
    Vector3 bl = new Vector3(b, b, 0f);
    Vector3 br = new Vector3(b, max, 0f);
    Vector3 tr = new Vector3(max, max, 0f);
    Vector3 tl = new Vector3(max, b, 0f);
    Vector3 norm = new Vector3(0f, 0f, 1f);
    mpb.rect(bl, tl, tr, br, norm);
    billboardTestModel = mb.end();
}
项目:gdx-proto    文件:Shadow.java   
public static void init() {
    list = new Array<>();
    ModelBuilder mb = new ModelBuilder();
    Vector3 norm = new Vector3(0f, 1f, 0f);
    Texture texture = Assets.manager.get("textures/shadow.png", Texture.class);
    Material material = new Material(TextureAttribute.createDiffuse(texture));
    material.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.7f));
    //material.set(new DepthTestAttribute(0)); // disable depth testing
    long attr = Usage.Position | Usage.TextureCoordinates;
    float s = 1f;
    model = mb.createRect(
            -s, 0f, -s,// bl
            -s, 0f, s, // tl
            s, 0f, s,  // tr
            s, 0f, -s,  // br
            norm.x, norm.y, norm.z,
            material,
            attr
    );
}
项目:gaiasky    文件:ModelBuilder2.java   
public Model createIcoSphere(float radius, int recursion, boolean flipNormals, boolean hardEdges, int primitiveType, final Material material, final long attributes) {
    begin();
    int nfaces = (int) (10 * Math.pow(2, 2 * recursion - 1));
    if (nfaces * 3 <= Short.MAX_VALUE) {
        // All in one part
        part("icosphere", primitiveType, attributes, material).icosphere(radius, recursion, flipNormals, hardEdges);
    } else {
        // Separate in more than one part
        int maxfaces = Short.MAX_VALUE / 3;
        int chunks = nfaces / maxfaces + 1;
        for (int i = 0; i < chunks; i++) {
            // Chunk i
            int startFace = i * maxfaces;
            part("icosphere", primitiveType, attributes, material).icosphere(radius, recursion, flipNormals, hardEdges, startFace, maxfaces);
        }

    }
    return end();
}
项目:gaiasky    文件:ModelBuilder2.java   
@Deprecated
public static Model createFromMesh(final Mesh mesh, int indexOffset, int vertexCount, int primitiveType, final Material material) {
    Model result = new Model();
    MeshPart meshPart = new MeshPart();
    meshPart.id = "part1";
    meshPart.offset = indexOffset;
    meshPart.size = vertexCount;
    meshPart.primitiveType = primitiveType;
    meshPart.mesh = mesh;

    NodePart partMaterial = new NodePart();
    partMaterial.material = material;
    partMaterial.meshPart = meshPart;
    Node node = new Node();
    node.id = "node1";
    node.parts.add(partMaterial);

    result.meshes.add(mesh);
    result.materials.add(material);
    result.nodes.add(node);
    result.meshParts.add(meshPart);
    result.manageDisposable(mesh);
    return result;
}
项目:Cubes_2    文件:Assets.java   
private static PackedTextureSheet getPackedTextureSheet(AssetType... assetType) {
    if (Adapter.isDedicatedServer())
        return null;
    TexturePacker texturePacker = new TexturePacker(2048, 2048, 1, true);
    Pixmap pixmap;
    getPacketTextureSheetFor(assetType, texturePacker, pixmap);

    FileHandle fileHandle = assetsFolder.child("packed");
    fileHandle.mkdirs();
    Compatibility.get().nomedia(fileHandle);
    fileHandle = fileHandle.child(assetType[0].name() + ".cim");

    try {
        PixmapIO.writeCIM(fileHandle, texturePacker.getPixmap());
    } catch (GdxRuntimeException e) {
        Log.error("Failed to write packed image", e);
    }

    Texture texture = new Texture(fileHandle);
    texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
    PackedTextureSheet packedTextureSheet = new PackedTextureSheet(
            new Material(TextureAttribute.createDiffuse(texture)));
    packedTextureSheet.getMaterial().set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

    Map<Asset, TexturePacker.PackRectangle> rectangles = texturePacker.getRectangles();
    int num = 0;
    for (Map.Entry<Asset, TexturePacker.PackRectangle> entry : rectangles.entrySet()) {
        num++;
        TextureRegion textureRegion = new TextureRegion(texture, entry.getValue().x, entry.getValue().y,
                entry.getValue().width, entry.getValue().height);
        entry.getKey().setPackedTextureRegion(textureRegion, packedTextureSheet);
        packedTextureSheet.getPackedTextures().put(entry.getKey().toString(), textureRegion);
    }

    for (AssetType type : assetType) {
        type.setPackedTextureSheet(packedTextureSheet);
    }
    return packedTextureSheet;
}
项目:Planetbase    文件:StrategyGame.java   
@Override
public void create() {
    INSTANCE=this;

    Debug.dbg("Path: "+System.getProperty("user.dir"));

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    staticEntityBatch = new ModelBatch();

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    float cameraDist=0.8f;
    cam.position.set(cameraDist,cameraDist,cameraDist);
    cam.lookAt(0,0,0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    Assets.modelBuilder = new ModelBuilder();
    Model world = Assets.modelBuilder.createSphere(2f,2f,2f, 
            80, 80, /* 80x80 seems to be enough polys to look smooth */
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
    models.add(world);

    planetSurface = new ModelInstance(world);

    camController = new CameraController(cam);
    Gdx.input.setInputProcessor(camController);

    space=new Space();
}
项目:Planetbase    文件:StrategyGame.java   
public void renderSelectTooltip(){
    float radius=selectGroup+0.03f;
    ModelInstance sphere=new ModelInstance(Assets.modelBuilder.createSphere(radius, radius, radius
            ,(int)(100*radius),(int)(100*radius), //This can be lower-resolution
            new Material(ColorAttribute.createDiffuse(1,0,0,0.5f)),
            Usage.Position | Usage.Normal));
    sphere.transform.setToTranslation(-cam.direction.x, -cam.direction.y, -cam.direction.z);
    staticEntityBatch.render(sphere);
}
项目:thunderboard-android    文件:DemoMotionGdxAdapter.java   
public void turnOffLights() {
    for (Material mat : lightMaterials) {
        if (mat.has(ColorAttribute.Emissive)) {
            mat.remove(ColorAttribute.Emissive);
        }
    }
}
项目:nhglib    文件:PointSpriteSoftParticleBatch.java   
protected void allocRenderable() {
    renderable = new Renderable();
    renderable.meshPart.primitiveType = GL20.GL_POINTS;
    renderable.meshPart.offset = 0;
    renderable.material = new Material(new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA, 1f),
            new DepthTestAttribute(GL20.GL_LEQUAL, false), TextureAttribute.createDiffuse((Texture) null));
}
项目:nhglib    文件:LightProbe.java   
private void createMeshes() {
    ModelBuilder mb = new ModelBuilder();
    cubeModel = mb.createBox(1, 1, 1, new Material(),
            VertexAttributes.Usage.Position |
                    VertexAttributes.Usage.Normal |
                    VertexAttributes.Usage.TextureCoordinates);
    cubeMesh = cubeModel.meshes.first();

    G3dModelLoader modelLoader = new G3dModelLoader(new UBJsonReader());
    quadModel = modelLoader.loadModel(Gdx.files.internal("models/quad.g3db"));
    quadMesh = quadModel.meshes.first();
}
项目:nhglib    文件:NhgModelLoader.java   
@Override
public Model loadSync(AssetManager manager, String fileName, FileHandle file, P parameters) {
    ModelData data = null;
    synchronized (items) {
        for (int i = 0; i < items.size; i++) {
            if (items.get(i).key.equals(fileName)) {
                data = items.get(i).value;
                items.removeIndex(i);
            }
        }
    }
    if (data == null) return null;
    final Model result = new Model(data, new TextureProvider.AssetTextureProvider(manager));
    // need to remove the textures from the managed disposables, or else ref counting
    // doesn't work!
    Iterator<Disposable> disposables = result.getManagedDisposables().iterator();
    while (disposables.hasNext()) {
        Disposable disposable = disposables.next();
        if (disposable instanceof Texture) {
            disposables.remove();
        }
    }

    // Automatically convert all materials to PBR
    for (Material material : result.materials) {
        TextureAttribute textureAttribute = (TextureAttribute) material.get(TextureAttribute.Diffuse);

        if (textureAttribute != null) {
            material.set(PbrTextureAttribute.createAlbedo(textureAttribute.textureDescription.texture));
        }
    }

    data = null;
    return result;
}
项目:LibGDX-PBR    文件:PBRTestAPP.java   
Material createMaterial(String materialName){
    Material material=new Material();
    material.set(PBRTextureAttribute.createAlbedo(new Texture("materials/" + materialName + "_Base_Color.png")));
    material.set(PBRTextureAttribute.createMetallic(new Texture("materials/" + materialName + "_Metallic.png")));
    material.set(PBRTextureAttribute.createRoughness(new Texture("materials/" + materialName + "_Roughness.png")));
    material.set(PBRTextureAttribute.createAmbientOcclusion(new Texture("materials/" + materialName + "_Ambient_Occlusion.png")));
    material.set(PBRTextureAttribute.createHeight(new Texture("materials/" + materialName + "_Height.png")));
    material.set(PBRTextureAttribute.createNormal(new Texture("materials/" + materialName + "_Normal.png")));

    return material;
}
项目:LibGDX-PBR    文件:PBRTestAPP.java   
public static Renderable createRenderableFromMesh(Mesh mesh, Material material, Shader shader, Environment environment) {
    Renderable outRend=new Renderable();
    outRend.meshPart.mesh=mesh;
    outRend.meshPart.primitiveType=GL20.GL_TRIANGLES;
    if(material!=null) outRend.material=material;
    if(environment!=null) outRend.environment=environment;
    outRend.meshPart.offset=0;
    //strada.shader=elrShader;
    if(shader!=null) outRend.shader=shader;
    outRend.meshPart.size=mesh.getNumIndices();
    return outRend;
}