游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3868|回复: 7

莫名其妙~!关于材质

[复制链接]

3

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2008-7-26 20:02:00 | 显示全部楼层 |阅读模式
class ProjectiveDecalApplication : public ExampleApplication
{
protected:
        void createScene()
        {
                // Set ambient light
                mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));

                // Create a light
                Light* l = mSceneMgr->createLight("MainLight");
                l->setPosition(20,80,50);

                // Position the camera
                mCamera->setPosition(60, 200, 70);
                mCamera->lookAt(0,0,0);

                ent = mSceneMgr->createEntity("robot","robot.mesh");
                m_waterNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
                m_waterNode2->attachObject(ent1);
               
                // Make all of the materials in the head entities receive the decal
                for (unsigned int i = 0; i < ent1->getNumSubEntities(); i++)
                        makeMaterialReceiveDecal(ent1->getSubEntity(i)->getMaterialName());

                //m_waterNode2->setPosition(100,0,0);                //向X轴移动100个单位
        }
        void makeMaterialReceiveDecal(const String &matName)
        {
                // get the material
                mat = (MaterialPtr)MaterialManager::getSingleton().getByName(matName);
                // create a new pass in the material to render the decal
                Pass *pass = mat->getTechnique(0)->createPass();

                // set our pass to blend the decal over the model's regular texture
                pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
                pass->setDepthBias(1);

                // set the decal to be self illuminated instead of lit by scene lighting
                pass->setLightingEnabled(false);

                // set up the decal's texture unit
                TextureUnitState *texState = pass->createTextureUnitState("decal.png");
                texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
                texState->setTextureFiltering(FO_POINT, FO_LINEAR, FO_NONE);
        }

        // Create new frame listener
        void createFrameListener(void)
        {
                mFrameListener= new ProjectiveDecalListener(mWindow, mCamera);
                mRoot->addFrameListener(mFrameListener);
        }
};       
其运行效果如下:

这样看起来没有什么问题,但是如果把CreateScene()这个函数中的最后一行代码"m_waterNode2->setPosition(100,0,0);"的注释去掉的话,结果就奇怪了:

这是为什么呢?makeMaterialReceiveDecal函数是在机器人的材质脚本中添加一个渲染通道,decal.png应该始终和机器人的材质在一起才对呀,怎么移动机器人后,decal.png还留在原地呢???哪位大大可以给小弟解下惑啊~~?谢谢了先~~

1

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2008-7-27 06:29:00 | 显示全部楼层

Re:莫名其妙~!关于材质

你不去掉不就可以了么
明明可以为什么还要去掉呢

1

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2008-7-27 06:33:00 | 显示全部楼层

Re:莫名其妙~!关于材质

void makeMaterialReceiveDecal(const String &matName)
{
// get the material
mat = (MaterialPtr)MaterialManager::getSingleton().getByName(matName);
// create a new pass in the material to render the decal
Pass *pass = mat->getTechnique(0)->createPass();

// set our pass to blend the decal over the model's regular texture
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
pass->setDepthBias(1);

// set the decal to be self illuminated instead of lit by scene lighting
pass->setLightingEnabled(false);

// set up the decal's texture unit
TextureUnitState *texState = pass->createTextureUnitState("decal.png");
texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
texState->setTextureFiltering(FO_POINT, FO_LINEAR, FO_NONE);
}

// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new ProjectiveDecalListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};

我自己最近也在做游戏,但不知道为什么材质弄不上去
导入之后没有颜色
以上就是你的实现添加材质的功能的函数么
具体解释下吧

3

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
 楼主| 发表于 2008-7-27 11:15:00 | 显示全部楼层

Re: 莫名其妙~!关于材质

因为这样的话就只能在原点才能实现贴图了,如果把机器人移到想要的位置的话就会出现机器人到了那个位置,但贴图还在原点哦,这怎么能行嘛~~~

3

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
 楼主| 发表于 2008-7-27 11:29:00 | 显示全部楼层

Re:莫名其妙~!关于材质

makeMaterialReceiveDecal是中级教程六中的一段代码,大意是给所给的材质脚本加一个渲染通道,应该和直接在材质脚本中添加如下代码一样
pass
{
        scene_blend alpha_blend
        depth_bias 1.0
        lighting off
        texture_unit
        {
                texture decal.png
                tex_address_mode clamp
                filtering point linear none
        }
}

3

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
 楼主| 发表于 2008-7-27 11:34:00 | 显示全部楼层

Re:莫名其妙~!关于材质

不过因为上面的问题,所以我也不知道我说的是不是对的哈

4

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2010-1-8 09:01:00 | 显示全部楼层

Re:莫名其妙~!关于材质

这个问题解决了么?  我也出现了这个问题

4

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2010-1-8 09:03:00 | 显示全部楼层

Re:莫名其妙~!关于材质

这个问题解决了么?  我也出现了这个问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-16 08:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表