Jump to content

Shadow For Non-Animated, Controller-Parented Model


gamecreator
 Share

Recommended Posts

I'm trying to have my character have a shadow when parented to a controller. However, he is not animated. The shadow appears fine if I load him alone with just:

 

Model *model = Model::Load("Models/bot/bot.mdl");

 

However, when I parent him to a controller, there is no shadow. I've tried:

 

controller->SetShadowMode(Light::Dynamic);

 

which worked with my animated characters in other projects but not here. I've also tried to add the second argument (recursion) with both true and false. I also tried the same with the model.

 

The model itself has no children.

 

I also tried:

 

player.model->SetParent(NULL, true);

 

and while that frees it from the controller, it doesn't get a shadow back.

 

Also gave parenting another model to a controller a shot. No shadow also.

 

Any thoughts?

 

(I feel like I could get it to work if I add some bones to the character and pretend to animate it and switch the shaders to animated.)

Link to comment
Share on other sites

Long shot but I wonder if it's related to this bug Josh couldn't replicate:

 

http://www.leadwerks.com/werkspace/topic/14918-putting-a-script-on-my-player-removes-their-shadow/#entry101108

 

"In the...appearance tab change the view range to near, medium or far." and not Max

"It only applies to point and spot lights, not directional."

  • Upvote 1

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

What is your controller? A pivot? Why not just make the model the controller? In any case, it looks like when parenting, the child will inherit whatever the parent's shadow mode is set at and it will not allow you to override that. So either make the model the controller or set the controller's (pivot's?) shadow mode to dynamic/static/buffered/anything other than 0.

window = Window:Create("example",0,0,1024,768,513)

context = Context:Create(window)

world = World:Create()

camera = Camera:Create()

camera:SetRotation(35,0,0)

camera:Move(0,0,-8)

local light = DirectionalLight:Create()

light:SetRotation(35,35,0)

 

ground = Model:Box(10,1,10)

ground:SetPosition(0,-0.5,0)

ground:SetColor(0.0,0.25,0.0)

shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)

ground:SetShape(shape)

shape:Release()

ground:SetNavigationMode(true)

world:BuildNavMesh()

 

player = Pivot:Create()

player:SetShadowMode(Light.Dynamic)--remove this line to have no shadow on visiblecapsule

local visiblecapsule = Model:Cylinder(16,player)

visiblecapsule:SetScale(1,2,1)

visiblecapsule:SetPosition(0,1,0)

player:SetPosition(-4,0,0)

player:SetMass(1)

player:SetPhysicsMode(Entity.CharacterPhysics)

 

while window:KeyHit(Key.Escape)==false do

if window:Closed() then break end

 

player:GoToPoint(4,0,0,1.4,1)

Time:Update()

world:Update()

world:Render()

context:Sync(true)

end

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

So this is my code:

 


void playerclass::initialize(float xx, float yy, float zz, int which, bool localplayer)

{

x=xx, z=zz;

 

controller = Pivot::Create();

 

model = laserred = laserblue = sphere1 = sphere2 = NULL;

model = Model::Load("Models/bot/bot.mdl");

if(!model)

{

MessageBoxA(0, "Loading bot model has failed. Exiting.", "Error", 0);

exit(1);

}

model->SetPosition(0, 0.5, 0, false);

model->SetParent(controller, true);

model->SetRotation(0, 180, 0, true);

model->SetShadowMode(Light::Dynamic, true);

 

laserred = Model::Load("Models/bot/laserred.mdl");

if (!laserred)

{

MessageBoxA(0, "Loading red laser model has failed. Exiting.", "Error", 0);

exit(1);

}

laserred->SetPosition(0.0, 0.39, 0.58, false);

laserred->SetParent(controller, false);

laserred->Hide();

 

laserblue = Model::Load("Models/bot/laserblue.mdl");

if (!laserblue)

{

MessageBoxA(0, "Loading blue laser model has failed. Exiting.", "Error", 0);

exit(1);

}

laserblue->SetPosition(0.0, 0.39, 0.58, false);

laserblue->SetParent(controller, false);

laserblue->Hide();

 

// These 2 spheres form a triangle with the laser origin

// to detect rocks within the triangle

sphere1 = Model::Sphere();

sphere1->SetPosition(-5, 0, 5);

sphere1->SetParent(controller, false);

sphere1->Hide();

 

sphere2 = Model::Sphere();

sphere2->SetPosition(5, 0, 5);

sphere2->SetParent(controller, false);

sphere2->Hide();

 

controller->SetShadowMode(Light::Dynamic, true);

controller->SetPosition(xx, yy, zz, false);

controller->SetMass(1);

controller->SetPhysicsMode(Entity::CharacterPhysics);

}

 

The only light in the scene is the one that comes by default with a map you create. If I add my own light then a shadow does appear. But if I remember right, you're not supposed to have two directional lights in a scene. I'll see what happens if I take out the one that came with the map...

Link to comment
Share on other sites

The default directional light that is created with the new map is set to a static shadow mode (at least in my map). If you want to see shadows on dynamic objects then you have to set the directional light's shadow mode to static+dynamic. Entities that do not move should use the static shadow mode and entities that do move like your controller/model should have their shadow mode set to dynamic.

 

Refer to the remarks for Entity::SetShadowMode() for more information:

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetshadowmode-r826

 

On a side note, what is the extra boolean parameter you are using for SetShadowMode()? In any case, looking at your code, you should only have to set the controller's shadow mode if you are going to use parenting.

 

 

--Edit - If the directional light that is automatically inserted in new maps has its shadow mode set to static only, this probably should be changed to static+dynamic. It's interesting to note that if you add your own directional light to an Editor scene, then the directional light's shadow mode is automatically set to static+dynamic.

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Thank you. I'll take a look at the settings on the map light. Seems like that might be the problem.

 

And I'm probably not clear how dynamic is defined. I have rocks breaking (manually moved/rotated children) and the moving/rotating pieces animate shadows on the ground. I looked at your link but will re-read the descriptions with a clearer head.

 

As for the bool: sorry. It's a quick copy and paste job for this tournament from an attempt at a multiplayer game. The host would create a controller but the clients wouldn't (they would just position the character where the host tells them to).

  • Upvote 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...