Flexman Posted May 11, 2011 Share Posted May 11, 2011 I was going to use MaterialDrawCallback() to bind user skins for different vehicles. This callback is supposed to return a pointer to the entity being rendered no? Any attempt to access TEntity properties results in an exception even though it's not a null pointer. Not really sure what's going on with that. Function MaterialCallback(material:TMaterial, entity:TEntity) if (entity.material) // kablewie endif End Function Just wondered if anyone else has tried this and got it to work OK? Seemed like a reasonable way to create non-instanced player skins. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
LordHippo Posted January 27, 2012 Share Posted January 27, 2012 I also have the same problem. I'm using this in C and actually the entity is always NULL. However the number of times this callback is called is correct. Anyone have ever used this callback? Quote Ali Salehi | Programmer Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64 LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17 Link to comment Share on other sites More sharing options...
L B Posted January 29, 2012 Share Posted January 29, 2012 Confirming, tested in my C# implementation. I would also like this fixed somehow. Quote Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 This code is printing ............. Camera Directionallight Camera Directionallight Camera Directionallight Camera Directionallight Camera Directionallight Camera Directionallight Camera Directionallight Camera ........... Framework leadwerks.engine registerabstractpath AppDir Graphics 800,600 createworld cp=createpivot() cam=createcamera() entityparent cam,cp moveentity cam,vec3(0,5,-5) pointentity cam,cp b=createbuffer(800,600,BUFFER_COLOR|BUFFER_NORMAL|BUFFER_DEPTH) lt=createdirectionallight() moveentity lt,vec3(1,2,3) pointentity lt,cp c=createcube() mat=creatematerial() setmaterialcolor mat,vec4(1,0,0,1) paintentity c,mat Function on_paint(mat:tmaterial,ee:TList) For e:tentity=EachIn ee Print getentitykey(e,"class") Next End Function setMaterialCallback mat,on_paint,MATERIALCALLBACK_ENABLE Repeat If KeyHit(27) Or AppTerminate() End turnentity cp,vec3(0,.1,0) setbuffer b renderworld setbuffer backbuffer() renderlights b Flip 1 Forever seems like second function parameter is the list of cameras\lights Want to know how to use it myself Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2012 Share Posted January 30, 2012 Sorry, the docs were wrong. There is no second parameter in the callback: http://www.leadwerks.com/werkspace/page/Documentation/le2/_/command-reference/materials/materialdrawcallback-r295 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 Sorry, the docs were wrong. There is no second parameter in the callback: http://www.leadwerks...awcallback-r295 So then how in this callback to get from what entity was callback called? Because with only one material parameter seems it is unusfull for us Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2012 Share Posted January 30, 2012 There's not necessarily even an entity associated with every material. I would use the entity draw callback for anything that needs the entity. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 http://leadwerks.com/wiki/index.php?title=SetEntityCallback ENTITYCALLBACK_UPDATEMATRIX - will be called whenever an entity rotates or moves. ENTITYCALLBACK_FREE - will be called when the entity is freed. ENTITYCALLBACK_COLLISION - will be called when the entity collides with another entity (bodies and terrain only). ENTITYCALLBACK_UPDATE - will be called once each time UpdateWorld() is called. ENTITYCALLBACK_MESSAGERECEIVE - will be called when the entity receives a message. it's not here Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 I would use the entity draw callback for anything that needs the entity. How? Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
LordHippo Posted January 30, 2012 Share Posted January 30, 2012 I was talking about MATERIALCALLBACK_DRAW. The wiki says: Gets called for every instance that is drawn that has this material. Using this will disable fast instanced rendering for any entities with that material. So I think if the entity is not passed to the callback, it would be useless. So I assume it as a bug. Another question: will the entity draw callback called exactly when the entity is being drawn? For example if I change shader uniforms in this callback, will these changes be applied to each entity, or the last change to all the entities? Quote Ali Salehi | Programmer Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64 LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17 Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 I don't get how it works Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
LordHippo Posted January 30, 2012 Share Posted January 30, 2012 I don't get how it works It was the original question Aily. The entity is not being passed to the material draw callback. So any function on that entity will result in a crash. In C, the entity is always NULL. Quote Ali Salehi | Programmer Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64 LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17 Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 It was the original question Aily. The entity is not being passed to the material draw callback. So any function on that entity will result in a crash. In C, the entity is always NULL. As you can see - in my function in BMax - i don't do any with entity, line inside function is commented. And error spawn on renderworld. Good if it works in C. P.S. Yeah, i'm some mistaked with callback names before... Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
LordHippo Posted January 30, 2012 Share Posted January 30, 2012 As you can see - in my function in BMax - i don't do any with entity, line inside function is commented. And error spawn on renderworld. Good if it works in C. P.S. Yeah, i'm some mistaked with callback names before... Sorry. I didn't know that ' is for commenting in BMax. Yeah it's working, if the NULL entity is assumed correct Quote Ali Salehi | Programmer Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64 LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17 Link to comment Share on other sites More sharing options...
Aily Posted January 30, 2012 Share Posted January 30, 2012 Last news This function don't have entity, and don't be work as we supposed. Wiki is wrong, wee need always look only to http://www.leadwerks.com/werkspace/page/Documentation/le2/_/command-reference/ I maked not instanced materials, but for this i creating copy of mesh on HDD, load id, delete from HDD - have not instanced model, but materials is instaced. Parse all it surfaces, and same write copyes of materials to HDD, load it, assign, delete from HDD. Same with shaders... Looks like there is no another way. Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2012 Share Posted January 30, 2012 At the point materials and shaders are enabled in the rendering pipeline, the code has no idea what entities are being drawn. All it has is a 4x4 matrix. Materials are not enabled per-entity. They are enabled once for each batch of surfaces drawn. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Aily Posted January 31, 2012 Share Posted January 31, 2012 It easy to hack your engine for you Josh Just add funtion LoadUniqueMesh that will be add system time value to mesh,materials and shaders filenames before loading it. And engine will think - that it's absolute separate mesh with separate materials. And all will be happy Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.