<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DirectContext3D Colorized Triangles in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569285#M24213</link>
    <description>&lt;P&gt;Congratulations on solving this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it be possible to share a minimal generic sample and a screen snapshot or two for the community to see a&amp;nbsp;working example of using this API?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That might also offer a good opportunity to ensure that your information about the&amp;nbsp;&lt;SPAN&gt;untouched EffectInstance gains appropriate visibility.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Aug 2021 12:08:11 GMT</pubDate>
    <dc:creator>jeremy_tammik</dc:creator>
    <dc:date>2021-08-24T12:08:11Z</dc:date>
    <item>
      <title>DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10567609#M24210</link>
      <description>&lt;P&gt;I'm having trouble applying colors to triangles that are shown via a DirectContext3DServer. I use a ColorWithTransparency object as a basis. Lines working fine, but here is the issue with triangles:&lt;/P&gt;&lt;P&gt;I can apply the color via the EffectInstance, but only if I set it's Emissive Color through .SetEmissiveColor(). If I set all it's other colors like, Color, DiffuseColor, SpecularColor or AmbientColor it stays black. Changing transparency works fine. The biggest issue if I'd like to apply the colors per vertices it wont work. I'm using&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;VertexFormatBits.PositionNormalColored, and set for instance&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ColorWithTransparency(&lt;/SPAN&gt;&lt;SPAN&gt;255&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;200&lt;/SPAN&gt;&lt;SPAN&gt;) as it's color, but all triangles will be transparent black. Any idea what could be the issue? No exceptions thrown, all buffers are valid, the geometries are being shown, but without the right color applied.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 23 Aug 2021 21:57:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10567609#M24210</guid>
      <dc:creator>tamas.deri</dc:creator>
      <dc:date>2021-08-23T21:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10568510#M24211</link>
      <description>&lt;P&gt;Can you provide a minimal reproducible case for the development team to analyse?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a small motivation, note that doing so has often led to a solution in the past:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-ontology.html#2" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-ontology.html#2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 06:45:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10568510#M24211</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-08-24T06:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569060#M24212</link>
      <description>&lt;P&gt;Hi Jeremy!&lt;/P&gt;&lt;P&gt;The funny thing is that I tried to put together the reproducible case, and I've just found out what the issue was. Somehow I left a line in the code which set the EffectInstance's transparency, and I think if any property of the EffectInstance is set than it overrides all vertex properties. Thats whythe vertex colors got ignored, and it falled back to transparent black. Once I removed that line, and kept only the just-constructed EffectInstance it worked as intended.&lt;BR /&gt;PS.: This could be mentioned somewhere in the documentation that vertex level colorization can only be used with an untouched EffectInstance, even if it seems straightforward for me now.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 10:59:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569060#M24212</guid>
      <dc:creator>tamas.deri</dc:creator>
      <dc:date>2021-08-24T10:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569285#M24213</link>
      <description>&lt;P&gt;Congratulations on solving this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it be possible to share a minimal generic sample and a screen snapshot or two for the community to see a&amp;nbsp;working example of using this API?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That might also offer a good opportunity to ensure that your information about the&amp;nbsp;&lt;SPAN&gt;untouched EffectInstance gains appropriate visibility.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 12:08:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569285#M24213</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-08-24T12:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569646#M24214</link>
      <description>&lt;P&gt;Sure! This is only a partial code that updates the buffers if it is neccessary. The rest is similar to what is available at other sources regarding DirectContext3D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def update_buffer(self):
    if self.penetrations is None: return False
    try:
        lines = []
        triangles = []
        colors = []
        for pen_item in self.penetrations:
            if pen_item.proposed:
                primitives = pen_item.proposed.get_wireframe()
            else:
                primitives = pen_item.current.get_wireframe()
            lines.extend(primitives[0])
            triangles.extend(primitives[1])
            colors.append(pen_item.status_color)

        tri_f_bits = dc.VertexFormatBits.PositionNormalColored
        tri_vertex_format = dc.VertexFormat(tri_f_bits)

        tri_effect_instance = dc.EffectInstance(tri_f_bits)

        # If you try to handle transparency globally it will also 
        # overrides vertex colors, and overrides them to black
        
        # tri_effect_instance.SetTransparency(0.8)

        tri_vertex_buffer_size = \
            dc.VertexPositionNormalColored.GetSizeInFloats() \
            * len(triangles) * 3
        tri_vertex_buffer = dc.VertexBuffer(tri_vertex_buffer_size)

        tri_index_buffer_size = \
            dc.IndexTriangle.GetSizeInShortInts() * len(triangles)
        tri_index_buffer = dc.IndexBuffer(tri_index_buffer_size)

        tri_vertex_buffer.Map(tri_vertex_buffer_size)
        tri_index_buffer.Map(tri_index_buffer_size)
        tri_vertex_stream_p = \
            tri_vertex_buffer.GetVertexStreamPositionNormalColored()
        tri_index_stream_p = tri_index_buffer.GetIndexStreamTriangle()
        for triangle in triangles:
            triangle_index = triangles.index(triangle)
            first_idx = triangle_index * 3
            tri_vertex_stream_p.AddVertex(dc.VertexPositionNormalColored(
                triangle[1], triangle[0], colors[triangle_index / 12]
            ))
            tri_vertex_stream_p.AddVertex(dc.VertexPositionNormalColored(
                triangle[2], triangle[0], colors[triangle_index / 12]
            ))
            tri_vertex_stream_p.AddVertex(dc.VertexPositionNormalColored(
                triangle[3], triangle[0], colors[triangle_index / 12]
            ))
            tri_index_stream_p.AddTriangle(dc.IndexTriangle(
                first_idx,
                first_idx + 1,
                first_idx + 2
            ))
        tri_vertex_buffer.Unmap()
        tri_index_buffer.Unmap()

        self.triangle_buffer = (
            tri_vertex_buffer,
            tri_vertex_buffer_size,
            tri_index_buffer,
            tri_index_buffer_size,
            tri_vertex_format,
            tri_effect_instance,
            dc.PrimitiveType.TriangleList,
            0,
            len(triangles)
        )

        line_f_bits = dc.VertexFormatBits.PositionColored
        line_vertex_format = dc.VertexFormat(line_f_bits)

        line_effect_instance = dc.EffectInstance(line_f_bits)

        line_vertex_buffer_size = \
            dc.VertexPositionColored.GetSizeInFloats() * len(lines) * 2
        line_vertex_buffer = dc.VertexBuffer(line_vertex_buffer_size)

        line_index_buffer_size = \
            dc.IndexLine.GetSizeInShortInts() * len(lines)
        line_index_buffer = dc.IndexBuffer(line_index_buffer_size)

        line_vertex_buffer.Map(line_vertex_buffer_size)
        line_index_buffer.Map(line_index_buffer_size)
        line_vertex_stream_p = \
            line_vertex_buffer.GetVertexStreamPositionColored()
        line_index_stream_p = line_index_buffer.GetIndexStreamLine()
        for line in lines:
            line_index = lines.index(line)
            first_idx = line_index * 2
            line_vertex_stream_p.AddVertex(dc.VertexPositionColored(
                line.GetEndPoint(0), colors[line_index / 12]
            ))
            line_vertex_stream_p.AddVertex(dc.VertexPositionColored(
                line.GetEndPoint(1), colors[line_index / 12]
            ))
            line_index_stream_p.AddLine(dc.IndexLine(
                first_idx,
                first_idx + 1
            ))
        line_vertex_buffer.Unmap()
        line_index_buffer.Unmap()

        self.line_buffer = (
            line_vertex_buffer,
            line_vertex_buffer_size,
            line_index_buffer,
            line_index_buffer_size,
            line_vertex_format,
            line_effect_instance,
            dc.PrimitiveType.LineList,
            0,
            len(lines)
        )
        self.update_flag = False
        return True
    except:
        return False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: I've tried to reproduce the previous issue and provide screenshots, but I just couldn't. It is weird. I even reverted my whole branch to the state where it didn't work, but now it is working.&lt;/P&gt;&lt;P&gt;So... I have to withdraw everything I said, because I can't prove none of the above, and it remains and assumption.&lt;/P&gt;&lt;P&gt;At least there is some python example of DirectContext3D &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 14:27:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10569646#M24214</guid>
      <dc:creator>tamas.deri</dc:creator>
      <dc:date>2021-08-24T14:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10573902#M24215</link>
      <description>&lt;P&gt;I've managed to figure out why the vertex colors were not applied. It is still related to the EffectInstance, but it has nothing to do with its colors. The problem was that I've been using an EffectInstance created as&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;EffectInstance(&lt;/SPAN&gt;&lt;SPAN&gt;VertexFormatBits.PositionNormalColored) eventhough my displaystyle was not shaded. This made all my triangles black on non shaded views, but they did work fine on shaded views. So I added the following lines:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;            if any([
                    display_style == DB.DisplayStyle.Shading,
                    display_style == DB.DisplayStyle.ShadingWithEdges
            ]):
                tri_effect_instance = dc.EffectInstance(
                    dc.VertexFormatBits.PositionNormalColored
                )
            else:
                tri_effect_instance = dc.EffectInstance(
                    dc.VertexFormatBits.PositionColored
                )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now it works on all views as expected, and I was able to keep the vertices as&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;VertexPositionNormalColored in all cases. The EffectInstance did the trick by itself.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 21:53:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/10573902#M24215</guid>
      <dc:creator>tamas.deri</dc:creator>
      <dc:date>2021-08-25T21:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: DirectContext3D Colorized Triangles</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/11397256#M24216</link>
      <description>&lt;P&gt;Thank you very much, Tamas, for the nice sample code and in-depth research. Preserved here for posterity:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2022/09/point-clouds-coloured-triangles-and-faces.html#3" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2022/09/point-clouds-coloured-triangles-and-faces.html#3&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 09:50:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/directcontext3d-colorized-triangles/m-p/11397256#M24216</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-09-02T09:50:59Z</dc:date>
    </item>
  </channel>
</rss>

