Пример #1
0
void TextureManager::onUnloaded( const ResourceEvent& event )
{
    ImageHandle handleImage = HandleCast<Image>(event.handle);
    Image* image = handleImage.Resolve();

    if( image->getResourceGroup() != ResourceGroup::Images )
        return;

    if( textures.Find(image) == textures.End() )
        return;

    LogDebug( "Removing texture '%s'", image->getPath().CString() );

    removeTexture(image);
}
Пример #2
0
bool TextureAtlas::addImage(const ImageHandle& newImageHandle) 
{
    if(imageSubTextures.Find( newImageHandle ) != imageSubTextures.End())
        return true;

    Image* newImage = newImageHandle.Resolve();

    Rectangle newRect = rectanglePacker.Insert(newImage->getWidth()+1, newImage->getHeight()+1, gs_heuristic);

    if (newRect.height == 0 || newRect.width == 0){
        if (atlasSize >= atlasMaxSize)
            return false;

        atlasSize = std::min(atlasSize*2, atlasMaxSize);
        resizeAtlas(atlasSize);

        return addImage(newImageHandle);
    }

    newRect.width--;
    newRect.height--;

    addImage(newImageHandle,newRect);

    return true;
}
Пример #3
0
void TextureManager::onLoaded( const ResourceEvent& event )
{
    ImageHandle handleImage = HandleCast<Image>(event.handle);
    Image* image = handleImage.Resolve();

    if( image->getResourceGroup() != ResourceGroup::Images )
        return;

    if( textures.Find(image) == textures.End() )
        return;

    Texture* texture = textures[image].get();
    texture->setImage(handleImage);

    backend->uploadTexture(texture);
}
Пример #4
0
void TextureManager::onReloaded( const ResourceEvent& event )
{
    ImageHandle handleImage = HandleCast<Image>(event.handle);
    Image* newImage = handleImage.Resolve();

    if( newImage->getResourceGroup() != ResourceGroup::Images )
        return;

    Image* oldImage = (Image*) event.oldResource;

    if( textures.Find(oldImage) == textures.End() )
        return;

    LogDebug( "Reloading texture '%s'", newImage->getPath().CString() );

    Texture* texture = textures[oldImage].get();
    texture->setImage(handleImage);

    textures.Erase(oldImage);
    textures[newImage] = texture;
}
Пример #5
0
TexturePtr TextureManager::getTexture( const ImageHandle& imageHandle )
{
    Image* image = imageHandle.Resolve();

    if (TexturePtr texture = getTexture(image))
        return texture;

    // Create a new texture from image.
    Texture* texture = backend->createTexture();
    texture->setImage(imageHandle);

    textures[image] = texture;

    return texture;
}
Пример #6
0
void TextureAtlas::addImage(ImageHandle newImageHandle, Rectangle newRect)
{
    Image* newImage = newImageHandle.Resolve();

    bool wasRotated = newImage->getWidth() == newRect.height &&
                      newImage->getHeight() == newRect.width;

    Image* atlasImage = atlasImageHandle.Resolve();

    assert(newImage->getPixelFormat() == atlasImage->getPixelFormat());

    if (wasRotated)
        RotateImage(newImage,atlasImage,Vector2i(newRect.x,newRect.y));
    else
        atlasImage->setBuffer(newImage,Vector2i(newRect.x,newRect.y));

    SubTexture subTexture;
    subTexture.atlas = this;

    float bottom = (float)(newRect.y+newRect.height)/atlasSize;
    float top = (float)newRect.y/atlasSize;
    float right = (float)(newRect.x+newRect.width)/atlasSize;
    float left = (float)newRect.x/atlasSize;

    if(!wasRotated)
    {
        subTexture.leftTopUV = Vector2(left,top);
        subTexture.rightTopUV = Vector2(right,top);
        subTexture.rightBottomUV = Vector2(right,bottom);
        subTexture.leftBottomUV = Vector2(left,bottom);
    } 
    else 
    {
        subTexture.rightTopUV = Vector2(left,top);
        subTexture.rightBottomUV = Vector2(right,top);
        subTexture.leftBottomUV = Vector2(right,bottom);
        subTexture.leftTopUV = Vector2(left,bottom);
    }

    imageSubTextures[newImageHandle] = subTexture;
}
Пример #7
0
void init(){
  bool cOut = pa("-c"), dOut = pa("-d");
  
  if(cOut){
    colorOut.init(pa("-c"));
  }
  if(dOut){
    depthOut.init(pa("-d"));
  }
  
  if(cOut || dOut){
    prevGUI << (cOut ? Image().handle("color") : Dummy())
            << (dOut ? Image().handle("depth") : Dummy())
            << Create();
  }

  gui << Draw3D().handle("draw")
      << ( VBox().minSize(10,2)
           << FSlider(-10,10,0).out("x").label("translate x")
           << FSlider(-10,10,0).out("y").label("translate y")
           << FSlider(1.5,10,0).out("z").label("translate z")
           
           << FSlider(-4,4,0).out("rx").label("rotate x")
           << FSlider(-4,4,0).out("ry").label("rotate y")
           << FSlider(-4,4,0).out("rz").label("rotate z")

           << ((cOut||dOut) ? (const GUIComponent&)Button("show","hide").label("preview").handle("preview") 
               : (const GUIComponent&)Dummy() )
           << Button("reset view").handle("resetView")
         )
      << Show();

  
  if(cOut || dOut){
    gui["preview"].registerCallback(utils::function(&prevGUI,&GUI::switchVisibility));
    if(dOut){
      ImageHandle d = prevGUI["depth"];
      d->setRangeMode(ICLWidget::rmAuto);
    }
  }
  
  Camera defaultCam(Vec(4.73553,-3.74203,8.06666,1),
                    Vec(-0.498035,0.458701,-0.735904,1),
                    Vec(0.787984,-0.116955,-0.604486,1));
  scene.addCamera( !pa("-cam").as<bool>() ? defaultCam : Camera(*pa("-cam")));
  initDepthCam = scene.getCamera(0);
  
  if(pa("-ccam")){
    scene.addCamera(*pa("-ccam"));
    Mat D=scene.getCamera(0).getCSTransformationMatrix();
    Mat C=scene.getCamera(1).getCSTransformationMatrix();
    
    relTM = new Mat( C * D.inv() );
  }

  SceneObject* ground = SceneObject::cuboid(0,0,0,200,200,3);
  ground->setColor(Primitive::quad,GeomColor(100,100,100,255));
  
  scene.addObject(ground);
  if(pa("-object")){
    scene.addObject( (obj = new SceneObject(*pa("-object"))) );
  }else{
    scene.addObject( (obj = SceneObject::cube(0,0,3, 3) ) );
  }
  obj->setColor(Primitive::quad, GeomColor(0,100,255,255));
  obj->setColor(Primitive::triangle, GeomColor(0,100,255,255));
  obj->setColor(Primitive::polygon, GeomColor(0,100,255,255));
  obj->setVisible(Primitive::line | Primitive::vertex, false);
  
  gui["draw"].link(scene.getGLCallback(0));
  gui["draw"].install(scene.getMouseHandler(0));

  scene.setDrawCamerasEnabled(false);

  scene.addCamera(scene.getCamera(0));

}
Пример #8
0
void wxImageComboBox::addImage( const ImageHandle& handle )
{
    Image* image = handle.Resolve();
    Append( image->getPath() );
    images.push_back(handle);
}