394{
395 ImGui::Begin("Objects", &showObjectWindow);
396
397
399
400 int index = 0;
401 for (auto& entity : entities)
402 {
408
409 if (identity && transform)
410 {
411 std::string headerName = identity->GetName() + " " + std::to_string(identity->GetId());
412 if (ImGui::CollapsingHeader(headerName.c_str()))
413 {
414
415 XMVECTOR position = transform->GetPosition();
416 XMVECTOR rotation = transform->GetRotation();
417 XMVECTOR scale = transform->GetScale();
418
419 float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
420 std::string posLabel = "Position##" + std::to_string(identity->GetId());
421 if (ImGui::DragFloat3(posLabel.c_str(), pos))
422 {
423 transform->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
424 transform->UpdateWorldMatrix();
425 }
426
427 float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) };
428 std::string rotLabel = "Rotation##" + std::to_string(identity->GetId());
429 if (ImGui::DragFloat3(rotLabel.c_str(), rot))
430 {
431 transform->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f));
432 transform->UpdateWorldMatrix();
433 }
434
435 float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
436 std::string sclLabel = "Scale##" + std::to_string(identity->GetId());
437 if (ImGui::DragFloat3(sclLabel.c_str(), scl))
438 {
439 transform->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f));
440 transform->UpdateWorldMatrix();
441 }
442
443 ImGui::Separator();
444
445
446 if (render && render->GetModel())
447 {
448
449 std::vector<std::string> textureCategories = {
450 "Diffuse", "Normal", "Specular", "Alpha"
451 };
452
453 std::vector<TextureType> textureTypes = {
454 TextureType::Diffuse, TextureType::Normal,
455 TextureType::Specular, TextureType::Alpha
456 };
457
458
459 std::string textureChildId = "TextureChild##" + std::to_string(identity->GetId());
460 ImGui::BeginChild(textureChildId.c_str(), ImVec2(0, 200), true, ImGuiWindowFlags_HorizontalScrollbar);
461
462
463 for (int typeIndex = 0; typeIndex < textureCategories.size(); typeIndex++)
464 {
465 TextureType type = textureTypes[typeIndex];
466 std::string typeName = textureCategories[typeIndex];
467
468
469 std::string categoryLabel = typeName + "##" + std::to_string(identity->GetId());
470 ImGui::Text("%s:", typeName.c_str());
471 ImGui::SameLine();
472
473
474 int textureCount = 0;
475 while (render->GetModel()->GetTexture(type, textureCount) != nullptr)
476 {
477 textureCount++;
478 }
479
480
481 std::string groupId = "TextureGroup_" + std::to_string(identity->GetId()) + "_" + std::to_string(typeIndex);
482 ImGui::BeginGroup();
483 for (int texIndex = 0; texIndex < textureCount; texIndex++)
484 {
485 ID3D11ShaderResourceView* texture = render->GetModel()->GetTexture(type, texIndex);
486 if (texture)
487 {
488
489 std::string buttonId = "tex##" + std::to_string(identity->GetId()) + "_" +
490 std::to_string(typeIndex) + "_" +
491 std::to_string(texIndex);
492
493 if (ImGui::ImageButton(buttonId.c_str(), (ImTextureID)texture, ImVec2(48, 48)))
494 {
495
496 OPENFILENAME ofn;
497 WCHAR szFile[260] = {0};
498 ZeroMemory(&ofn, sizeof(ofn));
499 ofn.lStructSize = sizeof(ofn);
500 ofn.hwndOwner = NULL;
501 ofn.lpstrFile = szFile;
502 ofn.nMaxFile = sizeof(szFile);
503 ofn.lpstrFilter = L"Texture\0*.png;*.jpg;*.dds\0";
504 ofn.nFilterIndex = 1;
505 ofn.lpstrInitialDir = NULL;
506 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
507
508 if (GetOpenFileName(&ofn))
509 {
510
511 render->GetModel()->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, type, texIndex);
512 }
513 }
514
515
516 if (ImGui::IsItemHovered())
517 {
518 ImGui::BeginTooltip();
519 ImGui::Text("%s %d", typeName.c_str(), texIndex);
520 ImGui::Image((ImTextureID)texture, ImVec2(192, 192));
521 ImGui::EndTooltip();
522 }
523
524 ImGui::SameLine();
525 }
526 }
527
528
529 std::string addButtonLabel = "+##" + std::to_string(identity->GetId()) + "_" + std::to_string(typeIndex);
530 if (ImGui::Button(addButtonLabel.c_str(), ImVec2(48, 48)))
531 {
532
533 OPENFILENAME ofn;
534 WCHAR szFile[260] = {0};
535 ZeroMemory(&ofn, sizeof(ofn));
536 ofn.lStructSize = sizeof(ofn);
537 ofn.hwndOwner = NULL;
538 ofn.lpstrFile = szFile;
539 ofn.nMaxFile = sizeof(szFile);
540 ofn.lpstrFilter = L"Texture\0*.png;*.jpg;*.dds\0";
541 ofn.nFilterIndex = 1;
542 ofn.lpstrInitialDir = NULL;
543 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
544
545 if (GetOpenFileName(&ofn))
546 {
547
548 render->GetModel()->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
549 }
550 }
551
552 ImGui::EndGroup();
553 ImGui::Separator();
554 }
555
556 ImGui::EndChild();
557 }
558
559 ImGui::Separator();
560
561
562 std::string deleteLabel = "Delete##" + std::to_string(identity->GetId());
563 if (ImGui::Button(deleteLabel.c_str()))
564 {
565 app_->delete_entity_by_id(identity->GetId());
566
567 break;
568 }
569
570 ImGui::Separator();
571
572
573 if (shader)
574 {
575
576 const char* shaderOptions[] = {
577 "Enable Global Lighting",
578 "Enable Lighting",
579 "Enable Cel Shading",
580 "Enable Normal Mapping",
581 "Enable Specular Mapping",
582 "Enable Alpha Mapping"
583 };
584
585 std::vector<ecs::ShaderType> shaderTypes = {
586 ecs::ShaderType::SUNLIGHT,
587 ecs::ShaderType::LIGHTING,
588 ecs::ShaderType::CEL_SHADING,
589 ecs::ShaderType::NORMAL_MAPPING,
590 ecs::ShaderType::SPECULAR_MAPPING,
591 ecs::ShaderType::ALPHA_MAPPING
592 };
593
594
595 int currentShader = 0;
597 for (size_t i = 0; i < shaderTypes.size(); i++)
598 {
599 if (shaderTypes[i] == activeShader)
600 {
601 currentShader = static_cast<int>(i);
602 break;
603 }
604 }
605
606
607 std::string shaderComboId = "Shader Options##" + std::to_string(identity->GetId());
608 if (ImGui::BeginCombo(shaderComboId.c_str(), shaderOptions[currentShader]))
609 {
610 for (int i = 0; i < IM_ARRAYSIZE(shaderOptions); i++)
611 {
612
613 std::string shaderSelectableId = std::to_string(i) + "##shader_" + std::to_string(identity->GetId());
614 bool isSelected = (currentShader == i);
615 if (ImGui::Selectable(shaderOptions[i], isSelected))
616 {
617
618 currentShader = i;
619 shader->SetActiveShader(shaderTypes[i]);
620 }
621
622
623 if (isSelected)
624 ImGui::SetItemDefaultFocus();
625 }
626 ImGui::EndCombo();
627 }
628 }
629
630 ImGui::Separator();
631
632
633 bool isPhysicsEnabled = (
physics !=
nullptr);
634 std::string physicsLabel = "Physics##" + std::to_string(identity->GetId());
635
636 if (ImGui::Checkbox(physicsLabel.c_str(), &isPhysicsEnabled))
637 {
638 if (isPhysicsEnabled && !
physics)
639 {
640
643 }
644 else if (!isPhysicsEnabled &&
physics)
645 {
646
649 }
650 }
651
653 {
654
655 bool gravityEnabled =
physics->IsGravityEnabled();
656 std::string gravityLabel = "Gravity##" + std::to_string(identity->GetId());
657 if (ImGui::Checkbox(gravityLabel.c_str(), &gravityEnabled))
658 {
659 physics->SetGravityEnabled(gravityEnabled);
660 }
661
662
663 std::string typeLabel = "Type##" + std::to_string(identity->GetId());
665
666 if (ImGui::RadioButton(("None##" + std::to_string(identity->GetId())).c_str(),
667 type == ecs::ObjectType::Unknown))
668 {
669 identity->SetType(ecs::ObjectType::Unknown);
670 }
671 ImGui::SameLine();
672 if (ImGui::RadioButton(("Cube##" + std::to_string(identity->GetId())).c_str(),
673 type == ecs::ObjectType::Cube))
674 {
675 identity->SetType(ecs::ObjectType::Cube);
676 }
677 ImGui::SameLine();
678 if (ImGui::RadioButton(("Sphere##" + std::to_string(identity->GetId())).c_str(),
679 type == ecs::ObjectType::Sphere))
680 {
681 identity->SetType(ecs::ObjectType::Sphere);
682 }
683 ImGui::SameLine();
684 if (ImGui::RadioButton(("Terrain##" + std::to_string(identity->GetId())).c_str(),
685 type == ecs::ObjectType::Terrain))
686 {
687 identity->SetType(ecs::ObjectType::Terrain);
688 }
689
690 }
691
692 ImGui::Separator();
693 }
694 index++;
695 }
696 }
697
698 ImGui::End();
699}