基于OCC+QT的模型贴图测试(附接口)

其实这个功能在OCC自带的例子view3d中就有,不过这个例子是MFC例子,参考这个例子的条件下,整理出一个QT版本的贴图例子,参考效果如下:

 

 

 

 

 

 

案例如下:

//

申明:
Handle(AIS_Shape) Texturize(
        const TopoDS_Shape& aShape, Standard_CString aTFileName,
        Standard_Real toScaleU = 1.0, Standard_Real toScaleV = 1.0,
        Standard_Real toRepeatU = 1.0, Standard_Real toRepeatV = 1.0,
        Standard_Real originU = 0.0, Standard_Real originV = 0.0);

实现:
Handle(AIS_Shape) occQt::Texturize(const TopoDS_Shape& aShape,
    Standard_CString aTFileName,
    Standard_Real toScaleU,
    Standard_Real toScaleV,
    Standard_Real toRepeatU,
    Standard_Real toRepeatV,
    Standard_Real originU,
    Standard_Real originV)
{
    Handle(AIS_Shape) aTShape = new AIS_Shape(aShape);
    if (!aTShape->Attributes()->HasOwnShadingAspect())
    {
        aTShape->Attributes()->SetShadingAspect(new Prs3d_ShadingAspect());
    }
    aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap(new Graphic3d_Texture2Dmanual(TCollection_AsciiString((Standard_CString)(LPCTSTR)aTFileName)));
    aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();

    // do other initialization of AIS_Shape
    aTShape->SetTextureScaleUV(gp_Pnt2d(toScaleU, toScaleV));
    aTShape->SetTextureRepeatUV(gp_Pnt2d(toRepeatU, toRepeatV));
    aTShape->SetTextureOriginUV(gp_Pnt2d(originU, originV));

    aTShape->SetDisplayMode(AIS_Shaded);

    return aTShape;
}


案例:
void occQt::test()
{
    //测试纹理贴图  多文档
    if (QMdiSubWindow *activeSubWindow = ui.mdiArea->activeSubWindow())
    {
        Mdi *formDoc = qobject_cast<Mdi *>(activeSubWindow->widget());
        TopoDS_Shape aShape = formDoc->shape1;

        TopTools_IndexedMapOfShape aFaces;
        TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);

        // display original shape in shaded display mode
        Handle(AIS_Shape) aShapeIO = formDoc->anshape1;
        // Set increased polygon offset for the main shape to avoid depth collision with textured faces
        aShapeIO->SetPolygonOffsets(Aspect_POM_Fill, 1.5, 0.5);

        Handle(AIS_Shape) aTFace1 = Texturize(aShape, "carrelage1.gif", 1, 1, 3, 2);//第一个参数可以是topdds_face  topds_shape
        formDoc->myOccView->getContext()->Display(aTFace1, Standard_False);
        formDoc->myOccView->myView->Update();
    }
    
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值