Navigation

    • Register
    • Login
        No matches found
    • Search
    1. Home
    2. kisaf
    K

    kisaf

    @kisaf

    6
    Reputation
    21
    Posts
    115
    Profile views
    1
    Followers
    1
    Following
    Joined Last Online

    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    kisaf Follow

    Best posts made by kisaf

    Script : Harden edges of all UV borders (break Phong shading)

    Hi, I'd like to present you a simple script.
    It let you automatically select all UV borders and break their Phong shading, that might be useful for game modeling, especially with hardsurface props.
    More info about hard edges - http://www.polycount.com/forum/showthread.php?t=107196

    Unfortunately, the 'Texture View' window must be opened at least once for properly work 😞
    Just close 'Texture View' and continue work.

    Video: https://vimeo.com/317072443

    Download link: https://github.com/rocketjump4d/UV2PhongEdges

    posted in General Talk •
    RE: Script : Harden edges of all UV borders (break Phong shading)

    Hello guys,
    I rewritten script UV2PhongEdges (weird name, I know :D) from scratch. Now it should works much faster. Also UNDO finally works, yyyeeeey!

    You can download it here
    https://github.com/rocketjump4d/UV2PhongEdges

    And here is an example
    https://vimeo.com/447775062

    Also, if you just need to get edges indexes of all UV borders you can use this code:

    import c4d
    from c4d import utils
    
    def GetUVBorders(obj):
        edgesIndexes = set()
        abcd = tuple("abcd")
    
        tuvw = obj.GetTag(c4d.Tuvw)
        nbr = utils.Neighbor()
        nbr.Init(obj)
    
        # Create empty set for `edgesVV`
        # In this case `edgeVV` means `Edge between Vertex0 and Vertex1 (edgeVertexVertex)`
        # edgeVV is just a tuple(v0, v1), where v0 is index of the first vertex
        # and v1 is the second one
        allEdgesVV = set()
    
        for i in xrange(obj.GetPointCount()):
            # Find neighbor vertex for this one
            neighborIndexes = nbr.GetPointOneRingPoints(i)
    
            for ni in neighborIndexes:
                edgeTuple = (i, ni)
                allEdgesVV.add(edgeTuple)
    
        # At this point I've got a set of all `edgesVV` of the object
        # Something like this:
        # (0, 3)
        # (0, 5)
        # (5, 1)
    
        for edgeVV in allEdgesVV:
            # Find neighbour polygons for this edge
            # I called them polyA and polyB
            polyAIndex, polyBIndex = nbr.GetEdgePolys(edgeVV[0], edgeVV[1])
            polyA = obj.GetPolygon(polyAIndex)
    
            if polyBIndex is c4d.NOTOK:
                # There is no polyB. It means that this edge is border of the object
    
                # eiA stands for `Edge Index in polyA for current edgeVV`
                eiA = polyAIndex * 4 + polyA.FindEdge(edgeVV[0], edgeVV[1])
                edgesIndexes.add(eiA)
                continue
    
            polyB = obj.GetPolygon(polyBIndex)
    
            # piA0 stands for `Point Index in polyA for vertex edgeVV[0]`
            # the same for others
            piA0 = polyA.Find(edgeVV[0])
            piA1 = polyA.Find(edgeVV[1])
            piB0 = polyB.Find(edgeVV[0])
            piB1 = polyB.Find(edgeVV[1])
    
            # Replace "d" (3) to "c" (2) if polygon is triangle
            if polyA.IsTriangle() and piA0 == 3:
                piA0 = 2
            if polyA.IsTriangle() and piA1 == 3:
                piA1 = 2
            if polyB.IsTriangle() and piB0 == 3:
                piB0 = 2
            if polyB.IsTriangle() and piB1 == 3:
                piB1 = 2
    
            # Get UV coordinates for each point in each polygon
            uvCoordA0 = tuvw.GetSlow(polyAIndex)[abcd[piA0]]
            uvCoordA1 = tuvw.GetSlow(polyAIndex)[abcd[piA1]]
            uvCoordB0 = tuvw.GetSlow(polyBIndex)[abcd[piB0]]
            uvCoordB1 = tuvw.GetSlow(polyBIndex)[abcd[piB1]]
    
            if uvCoordA0 != uvCoordB0 or uvCoordA1 != uvCoordB1:
                eiA = polyAIndex * 4 + polyA.FindEdge(edgeVV[0], edgeVV[1])
                eiB = polyBIndex * 4 + polyB.FindEdge(edgeVV[0], edgeVV[1])
                edgesIndexes.add(eiA)
                edgesIndexes.add(eiB)
    
        return edgesIndexes
    

    Let me know if you find bugs.
    Btw, sorry any mistakes. My English is... meh

    posted in General Talk •
    RE: Is there a script/plugin for converting UV borders to Phong Edges?

    I've wrote it by myself 🙂
    Its presentation is here: https://plugincafe.maxon.net/topic/11336/script-harden-edges-of-all-uv-borders-break-phong-shading
    May be it'll be useful for someone
    Cheers

    posted in General Talk •

    Latest posts made by kisaf

    RE: fbx export plugin critical error

    Hi there, I have a similar problem. But I use R25 version.

    If I write
    exporterID[c4d.FBXEXPORT_SDS] = True or exporterID[c4d.FBXEXPORT_SDS] = False
    I get error
    AttributeError: parameter set failed

    If I comment or remove this line, export works fine.

    Maybe I should create a new topic with this issue.

    posted in Cinema 4D SDK •
    Files and modules organization

    Hello there

    There is my main module A. It should use a module B (located in the same folder) and Python's standart module YAML (which doesn't exist by default).
    Whats the best solution? Should I just download YAML and copy it to module A folder?

    Right now module A is placed here

    %user%\AppData\Roaming\Maxon\Maxon Cinema 4D R25\library\scripts\

    I'm not sure, but maybe I should use another folder, e.g. E:\C4D_scripts and use environment variable C4DPYTHONPATH39?

    How do you orginize your files and modules?

    posted in Cinema 4D SDK •
    Where to report a bug?

    Hello guys,
    where I can report a bug?

    There are Bug Reports but it looks dead.

    posted in General Talk •
    RE: Mirror without duplicate using `MCOMMAND_MIRROR`

    @fritz thank you very much, it works!

    posted in Cinema 4D SDK •
    RE: Mirror without duplicate using `MCOMMAND_MIRROR`

    Roger that, thanks again.
    I wasn't sure that the developers were aware. Sorry for annoy you 🙂
    Cheers

    posted in Cinema 4D SDK •
    RE: Mirror without duplicate using `MCOMMAND_MIRROR`

    Hello guys,
    This bug is still exists in S24. I made a video to show how it worked before (R21) and now (S22, R23, S24).

    https://vimeo.com/558586168

    For test I used the script from this page. The only difference I made is decreased value from 1000.0 to 0. It's just for convenience.

    This script should mirrors selected object, when settings[c4d.MDATA_MIRROR_DUPLICATE] is False. It works in R21 and doesn't work in any late releases.
    Could you fix it? I'm still using R21 because of this bug 😞

    posted in Cinema 4D SDK •
    RE: Mirror without duplicate using `MCOMMAND_MIRROR`

    @m_magalhaes
    Got it, thanks 🙂

    posted in Cinema 4D SDK •
    RE: Mirror without duplicate using `MCOMMAND_MIRROR`

    Hi, I've just tested this script in R23. It doesn't work 😞
    One of my own scripts cannot work without this function.
    Guys, you're really awesome! I love C4D, and hope you can fix it 😄

    May be I can help somehow? I can upload the example scene, if you need it.

    posted in Cinema 4D SDK •
    RE: Script : Harden edges of all UV borders (break Phong shading)

    Hello guys,
    I rewritten script UV2PhongEdges (weird name, I know :D) from scratch. Now it should works much faster. Also UNDO finally works, yyyeeeey!

    You can download it here
    https://github.com/rocketjump4d/UV2PhongEdges

    And here is an example
    https://vimeo.com/447775062

    Also, if you just need to get edges indexes of all UV borders you can use this code:

    import c4d
    from c4d import utils
    
    def GetUVBorders(obj):
        edgesIndexes = set()
        abcd = tuple("abcd")
    
        tuvw = obj.GetTag(c4d.Tuvw)
        nbr = utils.Neighbor()
        nbr.Init(obj)
    
        # Create empty set for `edgesVV`
        # In this case `edgeVV` means `Edge between Vertex0 and Vertex1 (edgeVertexVertex)`
        # edgeVV is just a tuple(v0, v1), where v0 is index of the first vertex
        # and v1 is the second one
        allEdgesVV = set()
    
        for i in xrange(obj.GetPointCount()):
            # Find neighbor vertex for this one
            neighborIndexes = nbr.GetPointOneRingPoints(i)
    
            for ni in neighborIndexes:
                edgeTuple = (i, ni)
                allEdgesVV.add(edgeTuple)
    
        # At this point I've got a set of all `edgesVV` of the object
        # Something like this:
        # (0, 3)
        # (0, 5)
        # (5, 1)
    
        for edgeVV in allEdgesVV:
            # Find neighbour polygons for this edge
            # I called them polyA and polyB
            polyAIndex, polyBIndex = nbr.GetEdgePolys(edgeVV[0], edgeVV[1])
            polyA = obj.GetPolygon(polyAIndex)
    
            if polyBIndex is c4d.NOTOK:
                # There is no polyB. It means that this edge is border of the object
    
                # eiA stands for `Edge Index in polyA for current edgeVV`
                eiA = polyAIndex * 4 + polyA.FindEdge(edgeVV[0], edgeVV[1])
                edgesIndexes.add(eiA)
                continue
    
            polyB = obj.GetPolygon(polyBIndex)
    
            # piA0 stands for `Point Index in polyA for vertex edgeVV[0]`
            # the same for others
            piA0 = polyA.Find(edgeVV[0])
            piA1 = polyA.Find(edgeVV[1])
            piB0 = polyB.Find(edgeVV[0])
            piB1 = polyB.Find(edgeVV[1])
    
            # Replace "d" (3) to "c" (2) if polygon is triangle
            if polyA.IsTriangle() and piA0 == 3:
                piA0 = 2
            if polyA.IsTriangle() and piA1 == 3:
                piA1 = 2
            if polyB.IsTriangle() and piB0 == 3:
                piB0 = 2
            if polyB.IsTriangle() and piB1 == 3:
                piB1 = 2
    
            # Get UV coordinates for each point in each polygon
            uvCoordA0 = tuvw.GetSlow(polyAIndex)[abcd[piA0]]
            uvCoordA1 = tuvw.GetSlow(polyAIndex)[abcd[piA1]]
            uvCoordB0 = tuvw.GetSlow(polyBIndex)[abcd[piB0]]
            uvCoordB1 = tuvw.GetSlow(polyBIndex)[abcd[piB1]]
    
            if uvCoordA0 != uvCoordB0 or uvCoordA1 != uvCoordB1:
                eiA = polyAIndex * 4 + polyA.FindEdge(edgeVV[0], edgeVV[1])
                eiB = polyBIndex * 4 + polyB.FindEdge(edgeVV[0], edgeVV[1])
                edgesIndexes.add(eiA)
                edgesIndexes.add(eiB)
    
        return edgesIndexes
    

    Let me know if you find bugs.
    Btw, sorry any mistakes. My English is... meh

    posted in General Talk •
    Mirror without duplicate using `MCOMMAND_MIRROR`

    Hello guys,
    It's something weird with MCOMMAND_MIRROR in S22.

    This script (thanks to m_adam) duplicates and mirrors the object.

    import c4d
    
    
    def main():
        # Checks if selected object is valid
        if op is None:
            raise ValueError("op is none, please select one object.")
    
        # Defines some general settings, take care MDATA_MIRROR_VALUE, MDATA_MIRROR_SYSTEM and MDATA_MIRROR_PLANE
        settings = c4d.BaseContainer()
        settings[c4d.MDATA_MIRROR_DUPLICATE] = True
        settings[c4d.MDATA_MIRROR_SELECTIONS] = True
        settings[c4d.MDATA_MIRROR_ONPLANE] = True
        settings[c4d.MDATA_MIRROR_WELD] = True
        settings[c4d.MDATA_MIRROR_TOLERANCE] = 0.01
    
        # Corresponds to MDATA_MIRROR_VALUE, MDATA_MIRROR_SYSTEM and MDATA_MIRROR_PLANE
        value = 1000.0
        system = 0 # 0 = Object, 1 = World
        plane = 1 # 0 = XY, 1 = ZY, 2 = XZ
    
        if not 0 <= system < 2:
            raise ValueError("System can only be 0 or 1")
    
        # Buffer position vector
        pos = c4d.Vector()
    
        # Calculates Local (Object) coordinates
        if system == 0:
            globalMatrix = op.GetMg()
            if plane == 0:
                pos = globalMatrix.v3
            elif plane == 1:
                pos = globalMatrix.v1
            elif plane == 2:
                pos = globalMatrix.v2
    
            settings[c4d.MDATA_MIRROR_POINT] = globalMatrix.off + pos * value
            settings[c4d.MDATA_MIRROR_VECTOR] = pos
    
        # Calculates World coordinates
        elif system == 1:
            if plane == 0:
                pos = c4d.Vector(0.0, 0.0, 1.0)
            elif plane == 1:
                pos = c4d.Vector(1.0, 0.0, 0.0)
            elif plane == 2:
                pos = c4d.Vector(0.0, 1.0, 0.0)
    
            settings[c4d.MDATA_MIRROR_POINT] = pos * value
            settings[c4d.MDATA_MIRROR_VECTOR] = pos
    
        # Send the Modeling Operation
        res = c4d.utils.SendModelingCommand(c4d.MCOMMAND_MIRROR,
                                            [op],
                                            c4d.MODELINGCOMMANDMODE_ALL,
                                            settings,
                                            doc)
    
        c4d.EventAdd()
    
    
    if __name__ == "__main__":
        main()
    
    
    

    However, if I change

    settings[c4d.MDATA_MIRROR_DUPLICATE] = True
    

    to

    settings[c4d.MDATA_MIRROR_DUPLICATE] = False
    

    Script doesn't make anything.
    In R20 it works.
    Is it ok? Is there any way to just mirror the object without duplicate it?

    P.S. Also, if I use Mirror (https://help.maxon.net/index.html#5633) with unchecked Duplicate Points everything works (in S22).

    Cinema 4D S22.118 Windows 10

    posted in Cinema 4D SDK •