【问题标题】:Minko: how to apply material(texture) on 3d loaded modelMinko:如何在 3d 加载模型上应用材质(纹理)
【发布时间】:2016-06-22 16:47:41
【问题描述】:

我有一个我在引擎中加载的 fbx 模型,但是当我尝试以编程方式在这个模型上应用纹理时它不起作用,但它适用于像立方体这样的原始对象。

这就是我的工作

 auto fileLoaderComplete = sceneManager->assets()->loader()->complete()->connect([&](file::Loader::Ptr loader)

{


            auto chair = sceneManager->assets()->symbol(FBX_MODEL_FILENAME);


            //chair->addComponent(Transform::create());

            auto chairMaterial = material::BasicMaterial::create();

            chairMaterial->diffuseMap(sceneManager->assets()->texture(TEXTURE_FILENAME));


            chair->addComponent(Surface::create(

                 geometry::QuadGeometry::create(sceneManager->assets()->context()),                                                                                                                      
                 chairMaterial,                                                                                                                      
                 sceneManager->assets()->effect("effect/Basic.effect")

            ));



            chair->component<Transform>()->matrix(chair->component<Transform>()->matrix() * math::scale(math::vec3(0.005f)));

            // Add the symbol to the scene

            root->addChild(chair);

            }); 

但没有在模型上应用任何纹理。如何让它正常工作?

【问题讨论】:

    标签: model textures fbx uv-mapping minko


    【解决方案1】:

    我不知道您真正想要实现什么,但是这段代码将一个四边形添加到您的椅子模型的根节点上,上面有一个纹理。如果启用了三角形剔除并且您的相机没有面对这个四边形,那么您看不到任何变化是正常的。

    您需要做的是检索包含要纹理化的表面的节点并更新其材质。

    它应该看起来像这样:

    auto fileLoaderComplete = sceneManager->assets()->loader()->complete()->connect([&](file::Loader::Ptr loader)
    {
        auto chair = sceneManager->assets()->symbol(FBX_MODEL_FILENAME);
        auto texture = sceneManager->assets()->texture(TEXTURE_FILENAME);
    
        auto surfaceNodeSet = scene::NodeSet::create(chair)
            ->descendants(true)
            ->where([](scene::Node::Ptr n)
        {
            return n->hasComponent<Surface>();
        });
    
        for (auto surfaceNode : surfaceNodeSet->nodes())
        {
            auto surface = surfaceNode->component<Surface>();
            surface->material()->data()->set("diffuseMap", texture->sampler());
        }
    
        chair->component<Transform>()->matrix(chair->component<Transform>()->matrix() * math::scale(math::vec3(0.005f)));
    
        // Add the symbol to the scene
        root->addChild(chair);
    });
    

    【讨论】:

    【解决方案2】:

    感谢您的帮助https://stackoverflow.com/a/35874003/3278271

    我知道为什么在这种情况下,即使你使用surfaceNode->component()->material(),纹理仍然不起作用。 原因是我的 fbx 模型不包含 UV 映射。

    那么现在的问题是如何以编程方式定义 UV?

    在 Unity 中,您可以这样做http://forum.unity3d.com/threads/programmatically-generate-uv-map.26095/

    但是在 Minko 中怎么做呢?

    【讨论】:

      猜你喜欢
      • 2012-07-10
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2013-02-13
      • 2014-10-04
      • 1970-01-01
      相关资源
      最近更新 更多