Page 1 of 1

S3Dvertex

Posted: Mon Sep 15, 2008 2:55 pm
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?

Posted: Mon Sep 15, 2008 3:10 pm
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.

Posted: Mon Sep 15, 2008 4:47 pm
by arnir
I dont understand what do you think...
wait i put source code here

Posted: Fri Sep 19, 2008 1:17 pm
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; 
} 

Posted: Sat Sep 20, 2008 3:35 am
by vitek

Code: Select all

// assuming texture has transparency data (alhpa channel)
decal->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);

Posted: Sat Sep 20, 2008 8:49 am
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.

Posted: Sat Sep 20, 2008 9:35 am
by torleif
Use a PNG with an alpha channel.

Posted: Sat Sep 20, 2008 12:55 pm
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...

Posted: Sat Sep 27, 2008 8:37 am
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:

Posted: Sat Sep 27, 2008 9:56 am
by hybrid
Yo have to override the material methods of ISceneNode, especially getMaterialCount and getMaterial(i). Otherwise, no correct material support will happen.

Posted: Sat Sep 27, 2008 10:55 am
by arnir
thanks
now is all right :)

Posted: Wed Apr 28, 2010 3:14 am
by netpipe
Image

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

fully working 1.7 demo of this, Thanks Armen! :)