Skip to content

Commit 2d112ca

Browse files
authored
feat: add 3d model viewer (#164)
1 parent ec2b0e7 commit 2d112ca

File tree

15 files changed

+678
-1
lines changed

15 files changed

+678
-1
lines changed

docs/configure-cms.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To add the shop in your website selling items and services you have to:
5454
<br>
5555
4. **(optional)** install the plugin `myCred` to add **"virtual points"** in your website, this will allow you to define a relation between money and your virtual point, so any user can buy items in the shopt through virtual points and buy virtual points with €/$
5656

57-
![Shop](shop.png)
57+
![Shop](images/shop.png)
5858

5959
Besides items you can also sell:
6060

@@ -72,6 +72,24 @@ Besides items you can also sell:
7272

7373
**Note:** if you want to sell a cumulative item you can use the `SKU itemsend_ITEM-ID_stack`.
7474

75+
### 3D Model Viewer
76+
77+
In any product it is possible to enable/disable the 3D viewer via settings on Inventory -> 3D Viewer.
78+
79+
![3d viewer](images/3d-viewer-option.png)
80+
81+
It currently suports:
82+
- mounts/pets/companion under itemsend SKU
83+
- transmog items under transmog-item SKU
84+
85+
Examples:
86+
87+
<img src="images/3d-viewer-example-mount.png" alt="3d viewer mount" width="500"/>
88+
89+
<img src="images/3d-viewer-example-pet.png" alt="3d viewer pet" width="500"/>
90+
91+
<img src="images/3d-viewer-example-transmog.png" alt="3d viewer pet" width="500"/>
92+
7593
## Troubleshooting
7694

7795
For everything ask help on [Discord](https://discord.gg/gkt4y2x) in the channel `#acore-cms` (section `TOOLS`), you can also tag @Helias for any issue about this CMS.
266 KB
Loading
213 KB
Loading
214 KB
Loading

docs/images/3d-viewer-option.png

6.46 KB
Loading
File renamed without changes.

src/acore-wp-plugin/src/Hooks/WooCommerce/FieldElements.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,62 @@ public static function destAccount(): void {
114114
<?php
115115
}
116116

117+
public static function get3dViewer(int $itemId): void {
118+
119+
global $post;
120+
$custom_3d_checkbox = get_post_meta($post->ID, '_custom_3d_checkbox', true);
121+
122+
if ($custom_3d_checkbox !== 'yes') {
123+
return;
124+
}
125+
126+
?>
127+
<script>$ = jQuery;</script>
128+
<script src="https://wowgaming.altervista.org/modelviewer/scripts/viewer.min.js"></script>
129+
<script type="module">
130+
import { generateModels } from "<?= ACORE_URL_PLG . "web/libraries/wow-model-viewer/index.js" ?>";
131+
132+
function show3dModel(displayId, entity, inventoryType, race=1, gender=0) {
133+
let model;
134+
if (entity === 'item') {
135+
const character = {
136+
race,
137+
gender,
138+
skin: 0,
139+
face: 0,
140+
hairStyle: 0,
141+
hairColor: 0,
142+
facialStyle: 0,
143+
items: [
144+
[inventoryType, displayId],
145+
],
146+
};
147+
model = character;
148+
}
149+
else if (entity === 'npc') {
150+
model = {
151+
type: 8,
152+
id: displayId,
153+
};
154+
}
155+
156+
const wow3dviewerId = 'acore-3d-viewer-<?= $itemId ?>';
157+
const productElementCSSclass = '.woocommerce-product-gallery';
158+
document.querySelector(productElementCSSclass).innerHTML = '';
159+
document.querySelector(productElementCSSclass).style.backgroundColor='black';
160+
document.querySelector(productElementCSSclass).id = wow3dviewerId;
161+
generateModels(1, `#${wow3dviewerId}`, model);
162+
}
163+
164+
fetch('https://wowgaming.altervista.org/modelviewer/data/get-displayid.php?type=item&id=<?= $itemId ?>')
165+
.then(response => response.text())
166+
.then(data => {
167+
const [displayId, entity, inventoryType] = data.split(',');
168+
show3dModel(displayId, entity, inventoryType);
169+
});
170+
</script>
171+
172+
<?php
173+
}
174+
117175
}

src/acore-wp-plugin/src/Hooks/WooCommerce/ItemSend.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public static function before_add_to_cart_button() {
7474
return;
7575
}
7676

77+
FieldElements::get3dViewer($sku->itemId);
78+
7779
$current_user = wp_get_current_user();
7880

7981
if ($current_user) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/* 3D viewer custom fields */
4+
function add_custom_3d_checkbox_field() {
5+
woocommerce_wp_checkbox( array(
6+
'id' => '_custom_3d_checkbox',
7+
'label' => __('3D Viewer', 'woocommerce'),
8+
'description' => __('Check this box to enable the 3D viewer for this product.', 'woocommerce'),
9+
));
10+
}
11+
add_action('woocommerce_product_options_inventory_product_data', 'add_custom_3d_checkbox_field');
12+
13+
14+
function save_3d_checkbox_field($post_id) {
15+
$custom_checkbox = isset($_POST['_custom_3d_checkbox']) ? 'yes' : 'no';
16+
update_post_meta($post_id, '_custom_3d_checkbox', $custom_checkbox);
17+
}
18+
add_action('woocommerce_process_product_meta', 'save_3d_checkbox_field');
19+
?>

src/acore-wp-plugin/src/Hooks/WooCommerce/TransmogItemSend.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public static function before_add_to_cart_button() {
3434
return;
3535
}
3636

37+
FieldElements::get3dViewer($itemId);
38+
3739
$current_user = wp_get_current_user();
3840

3941
if ($current_user) {

0 commit comments

Comments
 (0)