0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

面積0ポリゴンを発見したい

Last updated at Posted at 2025-12-05

たまーにあるんですが

マージのし忘れだったりで面積が0になってしまっているポリゴン と遭遇します。

見た感じ判らないのですが、

  • UV展開時にUV領域も0になる。 そうするとたまにarnoldレンダラーに怒られる。
  • smoothを掛けると思ってた形状と違った感じになってしまう。

と、結構後々になって問題になってくるんですよね。

なので、面積0ポリゴンを探しあてたいなーと

image.png

標準機能でやってみる

まずは標準機能で何とかできないかやってみました。

select > use constraints でフィルタリングしてあげればなんかできないかなぁ・・・・と

Areaという項目がありました。多分面積・・・じゃないかなぁ
min = 0 max = 0 だと反応しませんが、 min = 0 max = 0.001 に設定すると

image.png

お 見つけられました。

スクリプトでやってみる

なーんかどっかでポリゴンの面積を取得するAPIを見たよーな気がしたので探してみました。

ありました。

def OpenMaya.MItMeshPolygon.getArea()
getArea(space=kObject) -> float
This method gets the area of the face
space (int) - World Space or Object Space

もっとそのまんまのやつもありました。

def OpenMaya.MItMeshPolygon.zeroArea()
zeroArea() -> bool
This method checks if its a zero area face

試しに zeroArea を使ってみます。

import maya.cmds as cmds
import maya.api.OpenMaya as om2

def checkZeroAreaFace(targets):    
    errorFace = []
    for target in targets:
        mesh_dagPath = om2.MGlobal.getSelectionListByName(target).getDagPath(0)
        
        if mesh_dagPath.hasFn(om2.MFn.kMesh)==False:
            continue
        
        FnShape = om2.MFnMesh(mesh_dagPath)        
        polyNum = FnShape.numPolygons

        it = om2.MItMeshPolygon(mesh_dagPath)
        
        for faceId in range(0,polyNum):
            it.setIndex(faceId)
            
            if it.zeroArea():
                errorFace.append(target + ".f["+str(faceId)+"]")

    return errorFace
    
checkZeroAreaFace(["pSphere1"])
# Result: []

あれー?

ちょっと面積を吐かせてみましょう。

import maya.cmds as cmds
import maya.api.OpenMaya as om2

def checkZeroAreaFace(targets):
    
    errorFace = []
    for target in targets:
        mesh_dagPath = om2.MGlobal.getSelectionListByName(target).getDagPath(0)
        
        if mesh_dagPath.hasFn(om2.MFn.kMesh)==False:
            continue
        
        FnShape = om2.MFnMesh(mesh_dagPath)        
        polyNum = FnShape.numPolygons

        it = om2.MItMeshPolygon(mesh_dagPath)
        
        for faceId in range(0,polyNum):
            it.setIndex(faceId)
            area = it.getArea()
            print(area)
            if it.zeroArea():
                errorFace.append(target + ".f["+str(faceId)+"]")

    return errorFace
    
checkZeroAreaFace(["pSphere1"])

結果はこんな感じ

0.011292681097984314
0.011292688548564911
0.011292683891952038
0.011292684823274612
0.011292683891952038
0.011292681097984314
0.01129268016666174
0.01129268016666174
0.01129267830401659
0.01129267830401659
0.011292675510048866
0.011292679235339165
0.011292673647403717
0.011292672716081142
0.011292674578726292
0.011292673647403717
0.011292674578726292
0.011292671784758568
0.011292672716081142
0.011292676441371441
0.018533241003751755
0.018533239141106606
0.018533237278461456
0.01853322982788086
0.01853323169052601
0.01853322982788086
0.01853322423994541
0.01853322796523571
0.018533222377300262
0.018533222377300262
0.01853322610259056
0.01853322610259056
0.018533222377300262
0.01853322610259056
0.01853322423994541
0.018533216789364815
0.01853322423994541
0.018533218652009964
0.018533214926719666
0.01853322982788086
0.025344422087073326
0.02534441649913788
0.025344422087073326
0.025344425812363625
0.025344425812363625
0.02534440904855728
0.02534440904855728
0.025344401597976685
0.025344397872686386
0.025344396010041237
0.025344397872686386
0.025344403460621834
0.02534439228475094
0.025344397872686386
0.025344401597976685
0.025344401597976685
0.025344396010041237
0.025344396010041237
0.025344394147396088
0.02534441649913788
0.03156059607863426
0.03156060352921486
0.03156058490276337
0.031560588628053665
0.031560592353343964
0.03156059607863426
0.03156057745218277
0.031560588628053665
0.03156058117747307
0.03156058117747307
0.03156058117747307
0.03156057745218277
0.031560562551021576
0.031560562551021576
0.031560562551021576
0.031560562551021576
0.031560566276311874
0.03156057745218277
0.03156057000160217
0.03156057372689247
0.03702438622713089
0.03702438995242119
0.03702438250184059
0.0370243601500988
0.0370243638753891
0.037024371325969696
0.0370243676006794
0.037024371325969696
0.0370243564248085
0.0370243564248085
0.0370243564248085
0.0370243676006794
0.037024352699518204
0.037024375051259995
0.037024348974227905
0.037024348974227905
0.0370243564248085
0.037024352699518204
0.037024348974227905
0.0370243676006794
0.04159156605601311
0.041591573506593704
0.041591573506593704
0.04159155860543251
0.04159156233072281
0.04159155860543251
0.04159155488014221
0.041591547429561615
0.04159155488014221
0.04159155488014221
0.04159155860543251
0.041591547429561615
0.04159155488014221
0.04159153625369072
0.04159153625369072
0.041591547429561615
0.04159155115485191
0.041591547429561615
0.04159153252840042
0.04159155115485191
0.04513682797551155
0.045136839151382446
0.04513683542609215
0.04513683170080185
0.04513682797551155
0.04513682425022125
0.04513682797551155
0.045136820524930954
0.04513681307435036
0.04513681307435036
0.04513680934906006
0.04513680934906006
0.04513680189847946
0.04513680934906006
0.04513680189847946
0.04513679817318916
0.045136794447898865
0.04513680562376976
0.04513680934906006
0.04513680934906006
0.047559481114149094
0.0475594736635685
0.0475594699382782
0.0475594736635685
0.0475594736635685
0.0475594662129879
0.0475594587624073
0.047559455037117004
0.0475594587624073
0.0475594587624073
0.0475594624876976
0.047559451311826706
0.04755944758653641
0.047559451311826706
0.047559451311826706
0.04755944758653641
0.047559451311826706
0.047559451311826706
0.04755944013595581
0.0475594587624073
0.04878893122076988
0.04878894239664078
0.04878893122076988
0.048788927495479584
0.048788927495479584
0.04878893494606018
0.04878890886902809
0.04878892004489899
0.04878890514373779
0.04878890886902809
0.04878891631960869
0.04878891259431839
0.04878890886902809
0.04878890886902809
0.04878890514373779
0.04878891259431839
0.048788897693157196
0.04878891631960869
0.048788901418447495
0.04878891631960869
0.04878893122076988
0.048788946121931076
0.048788927495479584
0.048788927495479584
0.048788927495479584
0.04878893122076988
0.04878891259431839
0.04878892004489899
0.04878890514373779
0.04878890514373779
0.04878891631960869
0.04878891631960869
0.04878890514373779
0.04878890886902809
0.04878890514373779
0.04878890514373779
0.048788897693157196
0.04878891631960869
0.048788901418447495
0.04878891631960869
0.047559481114149094
0.0475594736635685
0.047559481114149094
0.0475594736635685
0.0475594736635685
0.0475594736635685
0.0475594662129879
0.047559455037117004
0.0475594587624073
0.0475594587624073
0.0475594624876976
0.047559451311826706
0.047559451311826706
0.04755944758653641
0.047559451311826706
0.047559455037117004
0.0475594587624073
0.047559451311826706
0.04755944013595581
0.0475594587624073
0.04513682425022125
0.045136842876672745
0.04513682797551155
0.04513683170080185
0.04513682797551155
0.04513682425022125
0.045136820524930954
0.04513682425022125
0.04513680934906006
0.04513680934906006
0.04513681307435036
0.04513680562376976
0.04513680934906006
0.04513680934906006
0.04513680189847946
0.04513679817318916
0.045136794447898865
0.04513680934906006
0.04513680189847946
0.04513681307435036
0.04159156605601311
0.041591573506593704
0.041591569781303406
0.04159155860543251
0.04159156605601311
0.04159155115485191
0.041591547429561615
0.041591547429561615
0.04159155488014221
0.04159155488014221
0.04159155860543251
0.041591547429561615
0.04159155488014221
0.04159153625369072
0.02179870940744877
7.685547309677077e-09  < これ
8.008675500548179e-09  < これ
0.021798718720674515
0.04159153252840042
0.04159155115485191
0.03702438622713089
0.03702438995242119
0.03702438622713089
0.0370243601500988
0.0370243638753891
0.037024371325969696
0.0370243638753891
0.037024371325969696
0.0370243564248085
0.0370243564248085
0.0370243601500988
0.0370243638753891
0.037024352699518204
0.037024348974227905
0.0564512200653553
0.07788585126399994
0.07788588851690292
0.05645120516419411
0.03702434524893761
0.0370243676006794
0.03156060352921486
0.03156059607863426
0.031560588628053665
0.031560588628053665
0.031560592353343964
0.031560592353343964
0.03156058117747307
0.03156058490276337
0.03156057745218277
0.03156057745218277
0.03156057745218277
0.03156058490276337
0.031560566276311874
0.03156057372689247
0.03156057000160217
0.03156057000160217
0.03156057745218277
0.031560588628053665
0.03156057372689247
0.03156057372689247
0.025344420224428177
0.025344420224428177
0.025344422087073326
0.025344422087073326
0.025344422087073326
0.02534440904855728
0.025344407185912132
0.025344403460621834
0.025344397872686386
0.025344397872686386
0.025344405323266983
0.025344401597976685
0.025344394147396088
0.025344397872686386
0.025344401597976685
0.025344401597976685
0.025344396010041237
0.025344397872686386
0.025344394147396088
0.02534441277384758
0.018533241003751755
0.018533241003751755
0.018533235415816307
0.01853322796523571
0.01853322796523571
0.01853322982788086
0.018533220514655113
0.01853322610259056
0.018533220514655113
0.018533220514655113
0.01853322610259056
0.01853322796523571
0.018533222377300262
0.01853322423994541
0.018533218652009964
0.018533218652009964
0.01853322610259056
0.018533220514655113
0.018533214926719666
0.01853322982788086
0.011292682029306889
0.011292687617242336
0.011292683891952038
0.011292683891952038
0.011292682960629463
0.011292682029306889
0.011292679235339165
0.01129268016666174
0.011292679235339165
0.011292679235339165
0.011292675510048866
0.01129268016666174
0.011292675510048866
0.011292673647403717
0.011292673647403717
0.011292673647403717
0.011292673647403717
0.011292671784758568
0.011292673647403717
0.01129267830401659
0.003793081734329462
0.0037930812686681747
0.0037930821999907494
0.0037930805701762438
0.0037930808030068874
0.0037930808030068874
0.003793078940361738
0.003793079173192382
0.003793079173192382
0.003793079173192382
0.003793078940361738
0.003793078940361738
0.003793078940361738
0.0037930780090391636
0.00379307777620852
0.00379307777620852
0.003793077077716589
0.0037930787075310946
0.003793077077716589
0.0037930801045149565
0.0037930819671601057
0.0037930812686681747
0.0037930821999907494
0.0037930805701762438
0.0037930808030068874
0.0037930803373456
0.0037930794060230255
0.0037930794060230255
0.003793079173192382
0.003793079173192382
0.0037930787075310946
0.003793078940361738
0.0037930787075310946
0.00379307777620852
0.0037930775433778763
0.0037930782418698072
0.0037930773105472326
0.0037930782418698072
0.003793077077716589
0.0037930801045149565

多分この2つがほぼゼロ面積なんですが、zeroAreaはおそらく完全にゼロじゃないとひっかけてくれないようですね。

なので、getAreaを使いつつ数字を丸めて対応してみます。

import maya.cmds as cmds
import maya.api.OpenMaya as om2

def checkZeroAreaFace(targets,threshold = 4):
    
    errorFace = []
    for target in targets:
        mesh_dagPath = om2.MGlobal.getSelectionListByName(target).getDagPath(0)
        
        if mesh_dagPath.hasFn(om2.MFn.kMesh)==False:
            continue
        
        FnShape = om2.MFnMesh(mesh_dagPath)        
        polyNum = FnShape.numPolygons

        it = om2.MItMeshPolygon(mesh_dagPath)
        
        for faceId in range(0,polyNum):
            it.setIndex(faceId)            
            area = it.getArea()
            
            if round(area,threshold) == 0.0:                
                errorFace.append(target + ".f["+str(faceId)+"]")

    return errorFace
    
checkZeroAreaFace(["pSphere1"],4)
# Result: ['pSphere1.f[255]', 'pSphere1.f[256]']

取れました!

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?