index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { useResource } from "@/modules/resource";
  2. import { useQueditor } from "@queenjs-modules/queditor";
  3. import { switchSceneProdComp } from "@queenjs-modules/queditor/module/controls/Queen3dCtrl/actions/geom";
  4. import { Pack } from "@queenjs-modules/queditor/objects";
  5. import { List } from "@queenjs/ui";
  6. import { defineComponent } from "vue";
  7. import MatItem from "./MatItem";
  8. import MeshItem from "./MeshItem";
  9. export default defineComponent({
  10. setup() {
  11. const queditor = useQueditor();
  12. const resource = useResource();
  13. const { store } = resource;
  14. const replaceMesh = async (record: any) => {
  15. const data = await resource.treeController.selectOnePackScene();
  16. if (!data) return;
  17. console.log("replaceMesh=>", record);
  18. const slotId = record.Id || record.id;
  19. const meshConf = resource.store.meshSlots.find(
  20. (item) => item.id == slotId
  21. );
  22. if (meshConf) {
  23. meshConf.pack = data;
  24. } else {
  25. const meshSlot = { id: slotId, pack: data };
  26. resource.store.meshSlots.push(meshSlot);
  27. }
  28. queditor.actions.insertMesh(data);
  29. };
  30. const replaceMat = async (record: any) => {
  31. const mat = await resource.treeController.selectOneMat();
  32. if (!mat) return;
  33. clickMat(record);
  34. const matConf = resource.store.matSlots.find(
  35. (item) => item.id == record.id
  36. );
  37. if (matConf) {
  38. matConf.material = mat;
  39. } else {
  40. const matSlot = { id: record.id, material: mat };
  41. resource.store.matSlots.push(matSlot);
  42. }
  43. record.thumbnail = mat?.thumbnail?.url;
  44. const targetComp = getTargetProCom(record);
  45. if (!targetComp || !mat) return;
  46. queditor.actions.updatePackProductCompMat(targetComp, mat);
  47. };
  48. const getTargetProCom = (record: any) => {
  49. const source: Pack["source"] = queditor.store.pack;
  50. const targetPro = source.products[0];
  51. const targetComp = targetPro?.components.find(
  52. (c) => c.name == record.meshSlotName
  53. );
  54. return targetComp;
  55. };
  56. const switchComp = (compName: string) => {
  57. switchSceneProdComp.call(
  58. queditor.controls.queen3dCtrl,
  59. queditor.store.pack.scenes[0].products[0].id,
  60. compName
  61. );
  62. };
  63. const clickMesh = (item: any) => {
  64. resource.store.setActiveKey({ type: "mesh", id: item.Id });
  65. switchComp(item.meshName);
  66. };
  67. const clickMat = (item: any) => {
  68. switchComp(item.meshSlotName);
  69. resource.store.setActiveKey({ type: "mat", id: item.id });
  70. };
  71. queditor.actions.on("initQueen3dScene:success", () => {
  72. const app = queditor.controls.queen3dCtrl.queen3d.getAppInstance();
  73. app.on("tap:click", (geom: any) => {
  74. const compName = geom?._userdata?.name;
  75. const mesh: any = resource.store.treeData.find(
  76. (d: any) => d.meshName == compName
  77. );
  78. if (!mesh) {
  79. resource.store.setActiveKey({ type: "" });
  80. } else {
  81. clickMat(mesh.children[0]);
  82. }
  83. });
  84. });
  85. return () => {
  86. const Meshlist = store.treeData || [];
  87. return (
  88. <div class="w-300px flex flex-col">
  89. <div class="p-15px text-16px text-white border-dark-800 border-0 border-b-1 border-solid">
  90. 模型列表
  91. </div>
  92. <List
  93. data={Meshlist}
  94. gap="10px"
  95. class="scrollbar flex-1 py-15px px-15px"
  96. >
  97. {{
  98. item: (record: any) => (
  99. <div>
  100. <MeshItem
  101. record={record}
  102. active={record.Id == store.activeKeys.id}
  103. onReplace={replaceMesh}
  104. onClick={clickMesh}
  105. />
  106. <div class="grid gap-y-10px pt-10px pl-10px">
  107. {record.children.map((item: any) => (
  108. <MatItem
  109. key={item.id}
  110. record={item}
  111. active={item.id == store.activeKeys.id}
  112. onClick={clickMat}
  113. onReplace={replaceMat}
  114. />
  115. ))}
  116. </div>
  117. </div>
  118. ),
  119. loadmore: () => (
  120. <div class="text-center py-20px text-12px opacity-80">
  121. 没有更多了
  122. </div>
  123. ),
  124. }}
  125. </List>
  126. </div>
  127. );
  128. };
  129. },
  130. });