S3Dvertex

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

S3Dvertex

Post by arnir »

i am using decalSceneNode

gr8

but i have problemm with vertex-es on backround:
Image

(there is no problem with alpha, see second image with another vertex color)

Image

and my question is: how to hide vertex on the backround?
programmer is bad designer
designer is bad programmer
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You can't use the vertex alpha as that will make the entire image transparent, you'd probably be better off using a texture which has transparent sections that you don't want rendered and then using EMT_ALPHA_CHANNEL as the material type. So make the white bits in your decal texture there transparent.
Image Image Image
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

I dont understand what do you think...
wait i put source code here
programmer is bad designer
designer is bad programmer
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

my code is:

IRRLICHT 1.41


decalscenenode.h

Code: Select all

#include <irrlicht.h> 
#include <time.h>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
 
class DecalSceneNode : public scene::ISceneNode 
{ 
protected: 
   core::aabbox3d<f32> Box; 
   video::S3DVertex Vertices[4]; 
   video::SMaterial Material; 

public: 

DecalSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, core::triangle3df tri, core::vector3df intersection, video::ITexture* image,float size); 

      vector3df pointA; 
      vector3df pointB; 
      vector3df pointC; 
      float posA; 
      float posB; 
      float posC; 
      vector3df trinormal; 
      float basesize; 

       IVideoDriver* driver; 
    
       line3d<f32> line1; 
       vector3df v1; 
       vector3df v2; 
       line3d<f32> line2; 
       vector3df v3; 
              
       vector3df squarepA; 
       vector3df squarepB; 
       vector3df squarepC; 
       vector3df squarepD; 
       
       
         
      time_t c_time; 
      time_t d_time; 
      double lifeSpan; 

void setLifeSpan(double seconds); 

void OnRegisterSceneNode();

void render(); 
    
const core::aabbox3d<f32>& getBoundingBox() const; 

};
decalscenenode.cpp

Code: Select all

#include <irrlicht.h> 
#include "decalscenenode.h" 
#include "time.h" 

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

DecalSceneNode::DecalSceneNode(ISceneNode* parent, ISceneManager* mgr, triangle3df tri, vector3df intersection, ITexture* image, float size): ISceneNode(parent, mgr, 0) 
{            
      
      IVideoDriver* driver = SceneManager->getVideoDriver(); 
      basesize=size/2;
      time(&c_time);    
      lifeSpan=0; 
      
      Material.Wireframe = false; 
      Material.Lighting = false;
      Material.setTexture(0, image);
      
      SColor color(255,255,255,255);
      
      
      
      pointA=tri.pointA; 
      pointB=tri.pointB; 
      pointC=tri.pointC; 
      
      
      posA=intersection.X; 
      posB=intersection.Y; 
      posC=intersection.Z; 
      
      
      trinormal=tri.getNormal(); 
      trinormal=trinormal.normalize();   
      
       


       line3d<f32> line1(pointA, pointB); 
       vector3df v1 = line1.getVector().normalize(); 
       vector3df v2 = line1.getClosestPoint( pointC ); 
       line3d<f32> line2(v2,pointC); 
       vector3df v3 = line2.getVector().normalize(); 
              
       vector3df squarepA=(v1*-basesize)+trinormal*1+(v3*-basesize); 
       vector3df squarepB=squarepA+(v1*basesize*2); 
       vector3df squarepC=squarepA+(v1*basesize*2)+(v3*basesize*2); 
       vector3df squarepD=squarepA+(v3*basesize*2); 


       squarepA=squarepA+vector3df(posA,posB,posC); 
       squarepB=squarepB+vector3df(posA,posB,posC); 
       squarepC=squarepC+vector3df(posA,posB,posC); 
       squarepD=squarepD+vector3df(posA,posB,posC); 

       Vertices[0] = S3DVertex(squarepA.X,squarepA.Y,squarepA.Z, 1,0,0,color,1,0); 
       Vertices[1] = S3DVertex(squarepB.X,squarepB.Y,squarepB.Z, 1,0,0,color,1,1); 
       Vertices[2] = S3DVertex(squarepC.X,squarepC.Y,squarepC.Z, 1,0,0,color,0,1); 
       Vertices[3] = S3DVertex(squarepD.X,squarepD.Y,squarepD.Z, 1,0,0,color,0,0); 
       
       Box.reset(Vertices[0].Pos); 
       for (s32 i=1; i<4; ++i)
       { 
           Box.addInternalPoint(Vertices[i].Pos); 
       }
} 



void DecalSceneNode::setLifeSpan(double seconds){ 
lifeSpan=seconds; 
} 

void DecalSceneNode::OnRegisterSceneNode() 
{ 
if(lifeSpan>0)
{
if(difftime(time(NULL),c_time) > lifeSpan)
SceneManager->addToDeletionQueue(this);
} 


if (IsVisible) 
SceneManager->registerNodeForRendering(this); 
ISceneNode::OnRegisterSceneNode(); 
}

void DecalSceneNode::render() 
{       
u16 indices[] = { 0,1,2, 0,2,3}; 
IVideoDriver* driver = SceneManager->getVideoDriver(); 
driver->setMaterial(Material); 
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); 
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 2); 
} 

const core::aabbox3d<f32>& DecalSceneNode::getBoundingBox() const 
{          
return Box; 
} 
programmer is bad designer
designer is bad programmer
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

// assuming texture has transparency data (alhpa channel)
decal->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

Code: Select all

this->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
when I add this line to decalscenenode.cpp , effect is the same as on the first and second image...
background have the same color as vertex.
programmer is bad designer
designer is bad programmer
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Post by torleif »

Use a PNG with an alpha channel.
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

a solved my problemm
I use for material, not for sceneNode this:

Code: Select all

Material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
but always is something wrong:
see the different dots:

ImageImage

when I near to the wall, dots are black, else are normal.

I using ATMOsphere project (with ambient lights)
but I using also Lighting - false in decalscenenode...
programmer is bad designer
designer is bad programmer
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

yes, when I remove ATMOsphere (so that lighting)
decal is black ( SColor color(255,255,255,255); )

but I set lighting to false:

Code: Select all

setMaterialFlag(video::EMF_LIGHTING, false); 
Material.Lighting = false;
I HAVE:
Image


AND I WANT:
Image



please help me :cry:
programmer is bad designer
designer is bad programmer
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yo have to override the material methods of ISceneNode, especially getMaterialCount and getMaterial(i). Otherwise, no correct material support will happen.
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

thanks
now is all right :)
programmer is bad designer
designer is bad programmer
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Post by netpipe »

Image

http://www.xup.in/dl,17813176/decals.7z/

fully working 1.7 demo of this, Thanks Armen! :)
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
Post Reply