Giter Site home page Giter Site logo

Comments (7)

svenwoop avatar svenwoop commented on August 25, 2024

What geometry is the mesh supposed to be? It is likely just the one grass object, which is also seen in the instancing case. I cannot spot any obvious error in your code.

from embree.

freibold avatar freibold commented on August 25, 2024

You can also take a look at the instance array geometry tutorial

https://github.com/embree/embree/blob/master/tutorials/forest/forest_device.cpp

that we added in Embree 4.3.0. This tutorial does almost the same as you want to do but with trees instead of grass/herbs.

from embree.

StudenteChamp2 avatar StudenteChamp2 commented on August 25, 2024

@svenwoop @freibold Thanks for helping.
I updated the question because it could be confusing. So now the scene has only one mesh: the plane.

To recall I have 2 implementations. I don't get why the second is not working.

1) No instancing(WORKS)

Steps:
-->Create the scene(rtcNewScene)
-->Create a RTCGeometry(RTC_GEOMETRY_TYPE_TRIANGLE) for the plane
-->Set the geometry vertex and index buffers(using rtcSetSharedGeometryBuffer).
-->Commit the geometry(rtcCommitGeometry)
-->Attach the geometry to the scene(rtcAttachGeometryByID)
-->Commit the scene.

NoInstancing

2) Instancing(DOESN'T WORK)

Steps based on the instanced geometry tutorial :
-->Create the root scene
g_scene = rtcNewScene(g_device)

-->Create the instanced scene
g_scene1 = rtcNewScene(g_device)

-->Create a RTCGeometry for the plane
g_geometry = rtcNewGeometry(g_device, RTC_GEOMETRY_TYPE_TRIANGLE);

-->Set the geometry vertex and index buffers.

-->Commit the geometry
rtcCommitGeometry(g_geometry)

-->Attach the geometry to the instanced scene
rtcAttachGeometryByID(g_scene1, g_geometry, mesh->getFlatId())

--> Commit the instanced scene
rtcCommitScene(g_scene1)

-->Create a geometry instance.
g_instance0 = rtcNewGeometry(g_device, RTC_GEOMETRY_TYPE_INSTANCE)

-->Link the geometry instance to the instanced scene
rtcSetGeometryInstancedScene(g_instance0, g_scene1)

-->Set the instance transform
`
const float transform[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };

rtcSetGeometryTransform(g_instance0, 0, RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR, &transform[0]))`

-->Attach the instance to the root scene
rtcAttachGeometry(g_scene, g_instance0)

-->Commit the root scene
rtcCommitScene(g_scene))

Instancing

from embree.

svenwoop avatar svenwoop commented on August 25, 2024

Could you please provide a reproducer by modifying the instance geometry tutorial? It is not obvious what is wrong there and we would need a small reproducer to debug this.

from embree.

StudenteChamp2 avatar StudenteChamp2 commented on August 25, 2024

I managed to have it working by doing the same steps as what it is in the instanced geometry tutorial. So it works but I don't understand why. It look like this:

-->Create the root scene
g_scene = rtcNewScene(g_device)

-->Create the instanced scene
g_scene1 = rtcNewScene(g_device)

-->Create a RTCGeometry for the plane
g_geometry = rtcNewGeometry(g_device, RTC_GEOMETRY_TYPE_TRIANGLE);

-->Set the geometry vertex and index buffers.

-->Commit the geometry
rtcCommitGeometry(g_geometry)

-->Attach the geometry to the instanced scene
rtcAttachGeometryByID(g_scene1, g_geometry, mesh->getFlatId())

-->Release the geometry
rtcReleaseGeometry(g_geometry);

--> Commit the instanced scene
rtcCommitScene(g_scene1)

-->Create a geometry instance.
g_instance0 = rtcNewGeometry(g_device, RTC_GEOMETRY_TYPE_INSTANCE)

-->Attach the geometry instance to the root scene
rtcAttachGeometry(g_scene, g_instance0)

-->Release the geometry instance
rtcReleaseGeometry(g_instance0);

-->Set the instance transform
`
const float transform[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };

rtcSetGeometryTransform(g_instance0, 0, RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR, &transform[0]))`

--> Commit the instance geometry
rtcCommitScene(g_instance0)

-->Commit the root scene
rtcCommitScene(g_scene))

from embree.

StudenteChamp2 avatar StudenteChamp2 commented on August 25, 2024

@svenwoop How does rtcReleaseGeometry works?
Here we create the instance geometry then we free it inside the same function(device_init ):
https://github.com/embree/embree/blob/master/tutorials/instanced_geometry/instanced_geometry_device.cpp#L123

Then we later use the same geometry(we released) and we commit it:
https://github.com/embree/embree/blob/master/tutorials/instanced_geometry/instanced_geometry_device.cpp#L339

from embree.

svenwoop avatar svenwoop commented on August 25, 2024

The rtcReleaseGeometry decreases the reference counter on the geometry handle, thus you should not use that handle anymore. However, if you previously attach the handle to some scene, then the object itself will still be alive, as the scene itself increases the reference count on that geometry.

from embree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.