Skip to content

Commit

Permalink
Add create fbx to 3dtools
Browse files Browse the repository at this point in the history
  • Loading branch information
helderbetiol committed Mar 18, 2024
1 parent a66d423 commit 23716d4
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 56 deletions.
9 changes: 6 additions & 3 deletions 3dtools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ Package infomation in [requirements.txt](requirements.txt)
## Setup

To use `OGrEE-Tools/3dtools`, run the following commands to clone the repository and install the dependencies:
> Python version 3.10 is mandatory for the fbx creation functionality
```sh
git clone https://github.com/ditrit/OGrEE-Tools.git
cd OGrEE-Tools/3dtools
pip3 install -r ./requirements.txt
cd OGrEE-Tools/
python Converter/setup/setup.py
cd 3dtools
pip install -r ./requirements.txt
```

## Introduction
Expand Down Expand Up @@ -98,7 +101,7 @@ The user will be prompted with the following message:

```sh
Choose a component to detect.
Available commands: 'All', 'BMC', 'Disk_lff', 'Disk_sff', 'Disks', 'PSU', 'Serial', 'Slot_lp', 'Slot_normal', 'Slots', 'USB', 'VGA'
Available commands: 'All', 'RJ45', 'Disk_lff', 'Disk_sff', 'Disks', 'PSU', 'Serial', 'Slot_lp', 'Slot_normal', 'Slots', 'USB', 'VGA'
Enter 'finish' to output the JSON.

Command = ...
Expand Down
22 changes: 11 additions & 11 deletions 3dtools/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def dl_addComponents(self, pred):
Add components detected by YOLOv8 model.
"""

class_dic = {0: 'BMC', 1: 'Disk_lff', 2: 'Disk_sff', 3: 'PSU', 4: 'Serial', 5: 'Slot_lp', 6: 'Slot_normal', 7: 'USB', 8: 'VGA'}
class_dic = {0: 'RJ45', 1: 'Disk_lff', 2: 'Disk_sff', 3: 'PSU', 4: 'Serial', 5: 'Slot_lp', 6: 'Slot_normal', 7: 'USB', 8: 'VGA'}

boxes = pred[0].boxes.numpy()

Expand All @@ -32,7 +32,7 @@ def dl_addComponents(self, pred):
angle = 90
sim = component.conf[0]

self.components[position] = (compotype, compotype, angle, sim, dimensions)
self.components[position] = (compotype, compotype, "components", angle, sim, dimensions)
print(f" - {compotype} in : " + str([position, angle, sim]))

if len(boxes) == 0:
Expand Down Expand Up @@ -71,36 +71,36 @@ def writejson(self):
Generate JSON text of components in dict self.components
:return: 'servername.json' stocked in file api
"""
jsonraw = []
jsonraw = {"components":[], "slots":[]}
num = 0
if self._face == 'rear':
for k in self.componentsmm:
name, compotype, angle, similarity, _ = self.componentsmm[k]
name, compotype, compocategory, angle, similarity, _ = self.componentsmm[k]
composhape = self.sizetable[compotype] if angle == 0 else self.sizetable[compotype][::-1]
jsonraw.append({"location": name+str(num), "type": compotype, "elemOrient": 'horizontal' if angle == 0 else 'vertical',
jsonraw[compocategory].append({"location": name+str(num), "type": compotype, "elemOrient": 'horizontal' if angle == 0 else 'vertical',
'elemPos': [round(float(k[1]), 1), 0, round(float(k[0] - composhape[2]), 1)],
"elemSize": composhape, "labelPos": 'rear',
"color": "", "attributes": {"factor": "", 'similarity': str(similarity)}})
num += 1
else:
for k in self.componentsmm:
name, compotype, angle, similarity, _ = self.componentsmm[k]
name, compotype, compocategory, angle, similarity, _ = self.componentsmm[k]
composhape = self.sizetable[compotype] if angle == 0 else self.sizetable[compotype][::-1]
jsonraw.append({"location": str(num) + name, "type": compotype, "elemOrient": 'horizontal' if angle == 0 else 'vertical',
jsonraw[compocategory].append({"location": str(num) + name, "type": compotype, "elemOrient": 'horizontal' if angle == 0 else 'vertical',
'elemPos': [round(float(k[1]) - composhape[0], 1), round(756.67 - composhape[1], 1), round(float(k[0] - composhape[2]), 1)],
"elemSize": composhape, "labelPos": 'front',
"color": "", "attributes": {"factor": "", 'similarity': str(similarity)}})
num += 1
self.jsonraw = json.dumps(jsonraw, indent=4)
self.formatjson = jsonraw
return self.jsonraw
self.jsonraw = jsonraw
self.formatjson = json.dumps(jsonraw, indent=4)
return self.formatjson

def savejson(self):
# Step 1: Define the file path where you want to save the JSON data
file_path = 'api/'+self._name+'_'+self._face+'.json'
# Step 2: Write the dictionary to the JSON file
tools.jsondump(file_path, self.jsonraw)
print(self.jsonraw)
print(self.formatjson)

def getjson(self):
return self.formatjson
Expand Down
Loading

0 comments on commit 23716d4

Please sign in to comment.