-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path__init__.py
1096 lines (963 loc) · 52.4 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''
AFRAME Exporter for Blender
Copyright (c) 2023 Alessandro Schillaci
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
'''
'''
In collaboration with Andrea Rotondo, VR Expert since 1998
http://virtual-art.it - [email protected]
https://www.facebook.com/wox76
https://www.facebook.com/groups/134106979989778/
'''
'''
USAGE:
- create new Blender project
- install this addon get it here https://silverslade.itch.io/a-frame-blender-exporter
- open the addon and set your configuration
- add a CUSTOM PROPERTY (if needed)
- click on "Export A-Frame Project" button
- your project will be saved in the export directory
- launch "Start Serving" + "Open Preview" (to open a local browser)
- You can use others web server: eg. live-server" (install it with "npm install -g live-server") or "python -m SimpleHTTPServer"
AVAILABLE CUSTOM_PROPERTIES:
- AFRAME_CUBEMAP: if present, set reflections on to the mesh object (metal -> 1, rough -> 0)
- AFRAME_ANIMATION: aframe animation tag. Samples:
- property: rotation; to: 0 360 0; loop: true; dur: 10000;
- property: position; to: 1 8 -10; dur: 2000; easing: linear; loop: true;
- AFRAME_HTTP_LINK: html link when click on object
- AFRAME_VIDEO: target=mp4 video to show
- AFRAME_IMAGES: click to swap images e.g: {"1": "image1.jpg", "2": "image2.jpg"}
- AFRAME_SHOW_HIDE_OBJECT: click to show or hide another 3d object
THIRD PARTY SOFTWARE:
This Addon Uses the following 3rdParty software (or their integration/modification):
- Aframe Joystick - https://github.com/mrturck/aframe-joystick
- Aframe Components - https://github.com/colinfizgig/aframe_Components
- Icons - https://ionicons.com/
'''
bl_info = {
"name" : "Import-Export: a-frame webvr exporter",
"author" : "Alessandro Schillaci",
"description" : "Blender Exporter to AFrame WebVR application",
"blender" : (3, 5, 0),
"version" : (0, 0, 11),
"location" : "View3D",
"warning" : "",
"category" : "3D View"
}
import os
import bpy
import shutil
import math
from string import Template
import http.server
import urllib.request
import socketserver
import threading
import json
import random
import string
PORT = 8001
# Constants
PATH_INDEX = "index.html"
PATH_ASSETS = "assets/"
PATH_RESOURCES = "resources/"
PATH_MEDIA = "media/"
PATH_ENVIRONMENT = "env/"
PATH_LIGHTMAPS = "lightmaps/"
PATH_JAVASCRIPT = "js/"
AFRAME_ENABLED = "AFRAME_ENABLED"
AFRAME_HTTP_LINK = "AFRAME_HTTP_LINK"
AFRAME_ANIMATION = "AFRAME_ANIMATION"
AFRAME_VIDEO = "AFRAME_VIDEO"
AFRAME_IMAGES = "AFRAME_IMAGES"
AFRAME_DOWNLOAD = "AFRAME_DOWNLOAD"
AFRAME_VIDEO_AUTOPLAY = "AFRAME_VIDEO_AUTOPLAY"
AFRAME_VIDEO_STREAM = "AFRAME_VIDEO_STREAM"
assets = []
entities = []
lights = []
blender_lights = []
final_lights = ""
showstats = ""
# Need to subclass SimpleHTTPRequestHandler so we can serve cache-busting headers
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
http.server.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
class Server(threading.Thread):
instance = None
folder = ""
should_stop = False
def set_folder(self, folder):
self.folder = folder
def run(self):
Handler = MyHTTPRequestHandler
socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(("", PORT), Handler) as httpd:
os.chdir(self.folder)
while True:
if self.should_stop:
httpd.server_close()
break
httpd.handle_request()
def stop(self):
self.should_stop = True
# Consume the last handle_request call that's still pending
with urllib.request.urlopen(f'http://localhost:{PORT}/') as response:
html = response.read()
# Index html a-frame template
def default_template():
if not bpy.data.texts.get('index.html'):
tpl = bpy.data.texts.new('index.html')
tpl.from_string('''<!doctype html>
<html lang="en">
<!-- Generated automatically by AFRAME Exporter for Blender - https://silverslade.itch.io/a-frame-blender-exporter -->
<!-- MIT License: https://github.com/silverslade/aframe_blender_exporter/blob/master/LICENSE -->
<head>
<title>WebXR Application</title>
<link rel="icon" type="image/png" href="favicon.ico"/>
<meta name="description" content="3D Application">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://aframe.io/releases/${aframe_version}/aframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/donmccurdy/[email protected]/dist/aframe-extras.min.js"></script>
<script type="text/javascript" src="js/webxr.js"></script>
<script type="text/javascript" src="js/joystick.js"></script>
<script type="text/javascript" src="js/camera-cube-env.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body onload="init();">
<a-scene ${stats} ${joystick} ${render_shadows} ${renderer}>
<!-- Assets -->
<a-assets>${asset}
<img id="sky" src="./resources/sky.jpg">
<img id="icon-play" src="./resources/play.png">
<img id="icon-pause" src="./resources/pause.png">
<img id="icon-play-skip-back" src="./resources/play-skip-back.png">
<img id="icon-mute" src="./resources/mute.png">
<img id="icon-volume-low" src="./resources/volume-low.png">
<img id="icon-volume-high" src="./resources/volume-high.png">
</a-assets>
<!-- Entities -->
${entity}
<!-- Camera -->
<a-entity id="player"
position="0 -0.2 0"
movement-controls="speed: ${player_speed};">
<a-entity id="camera"
camera="near: 0.001"
position="0 ${player_height} 0"
look-controls="pointerLockEnabled: true">
<a-entity id="cursor" cursor="fuse: false;" animation__click="property: scale; startEvents: click; easing: easeInCubic; dur: 50; from: 0.1 0.1 0.1; to: 1 1 1"
position="0 0 -0.1"
geometry="primitive: circle; radius: 0.001;"
material="color: #CCC; shader: flat;"
${show_raycast}>
</a-entity>
</a-entity>
${vr_controllers}
</a-entity>
<!-- Lights -->
${lights}
<!-- Sky -->
${sky}
</a-scene>
</body>
</html>
<!-- Generated automatically by AFRAME Exporter for Blender - https://silverslade.itch.io/a-frame-blender-exporter -->
<!-- MIT License: https://github.com/silverslade/aframe_blender_exporter/blob/master/LICENSE -->
''')
class AframeExportPanel_PT_Panel(bpy.types.Panel):
bl_idname = "AFRAME_EXPORT_PT_Panel"
bl_label = "Aframe Exporter (v 0.0.11)"
bl_category = "Aframe"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, content):
scene = content.scene
layout = self.layout
layout.use_property_split=True
layout.use_property_decorate = False
#col = layout.column(align=False)
#col = layout.column(align=True)
#row = col.row()
#col.label(text="Exporter Settings", icon='NONE')
row = layout.row(align=True)
row.prop(scene, 'b_settings', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_settings') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="A-Frame", icon='NONE')
if scene.b_settings:
row = layout.row(align=True)
box = row.box()
#box.alignment = 'EXPAND'
box.prop(scene, "s_aframe_version")
box.prop(scene, "b_stats")
box.prop(scene, "b_joystick")
box.prop(scene, "b_vr_controllers")
#col.prop(scene, "b_hands")
box.prop(scene, "b_cubemap")
box.prop(scene, "b_camera_cube")
box.prop(scene, "b_show_env_sky")
box.prop(scene, "b_cubemap_background")
box.prop(scene, "s_cubemap_path")
box.prop(scene, "s_cubemap_ext")
#col.prop(scene, "b_blender_lights")
box.prop(scene, "b_cast_shadows")
box.prop(scene, "b_use_default_lights")
box.separator()
row = layout.row(align=True)
row.prop(scene, 'b_renderer', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_renderer') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="Renderer", icon='NONE')
if scene.b_renderer:
row = layout.row(align=True)
box = row.box()
box.prop(scene, "b_aa")
box.prop(scene, "b_colorManagement")
box.prop(scene, "b_physicallyCorrectLights")
box.separator()
row = layout.row(align=True)
row.prop(scene, 'b_player', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_player') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="Player", icon='NONE')
if scene.b_player:
row = layout.row(align=True)
box = row.box()
box.prop(scene, "b_raycast")
box.prop(scene, "f_raycast_length")
box.prop(scene, "f_raycast_interval")
box.prop(scene, "f_player_height")
box.prop(scene, "f_player_speed")
box.separator()
row = layout.row(align=True)
row.prop(scene, 'b_interactive', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_interactive') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="Interactive / Action", icon='NONE')
if scene.b_interactive:
row = layout.row(align=True)
box = row.box()
box.label(text="Add interactive or action to selected", icon='NONE')
box.operator("aframe.cubemap")
box.operator("aframe.rotation360")
box.operator("aframe.images")
row = box.column_flow(columns=2, align=False)
row.operator("aframe.show_hide_object")
row.prop(scene, "s_showhide_object", text="")
row = box.column_flow(columns=2, align=False)
row.operator("aframe.toggle_object")
row.prop(scene, "s_toggle_object", text="")
row = box.column_flow(columns=2, align=False)
row.operator("aframe.linkurl")
row.prop(scene, "s_link", text="")
row = box.column_flow(columns=2, align=False)
row.operator("aframe.videoplay")
row.prop(scene, "s_video", text="")
row = layout.row(align=True)
'''row.prop(scene, 'b_bake', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_bake') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="Bake", icon='NONE')
if scene.b_bake:
row = layout.row(align=True)
box = row.box()
#box.separator()
box.operator('aframe.delete_lightmap', text='0 Delete All lightmaps')
box.operator('aframe.prepare', text='1 Prepare Selection for Lightmapper')
box.operator('aframe.bake', text='2 Bake with Lightmapper')
box.operator('aframe.savelm', text='3 Save Lightmaps')
box.operator('aframe.clean', text='4 Clean Lightmaps')
#box.separator()
row = layout.row(align=True)
row.prop(scene, 'b_bake_lightmap', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_bake_lightmap') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="Create Lightmaps", icon='NONE')
if scene.b_bake_lightmap:
row = layout.row(align=True)
box = row.box()
#box.separator()
box.label(text="Enable github.com/Naxela/The_Lightmapper", icon='NONE')
box.prop(scene, "b_use_lightmapper")
box.prop(scene, "f_lightMapIntensity")
box.operator('aframe.delete_lightmap', text='0 Delete All lightmaps')
box.operator('aframe.prepare', text='1 Prepare Selection for Lightmapper')
box.operator('aframe.bake', text='2 Bake with Lightmapper')
box.operator('aframe.savelm', text='3 Save Lightmaps')
box.operator('aframe.clean', text='4 Clean Lightmaps')
#box.separator()
row = layout.row(align=True)
'''
row.prop(scene, 'b_export', text= "", icon="TRIA_DOWN" if getattr(scene, 'b_export') else "TRIA_RIGHT", icon_only=False, emboss=False)
row.label(text="Exporter", icon='NONE')
if scene.b_export:
row = layout.row(align=True)
box = row.box()
box.prop(scene, "s_project_name")
box.prop(scene, "export_path")
box.prop(scene, "b_export_single_model")
box.operator('aframe.clear_asset_dir', text='Clear Assets Directory')
# Show properties of selected object
row = layout.row(align=True)
row.label(text="Selected Object Properties", icon='NONE')
row = layout.row(align=True)
box = row.box()
obj = bpy.context.active_object
for K in obj.keys():
if K.startswith('AFRAME_'):
#box.label(text=K)
row = box.column_flow(columns=2, align=False)
row.label(text=K)
#row.prop(scene, "s_showhide_object", text="")
row.operator("aframe.delete_property").targetproperty=K
#box.prop(text=obj[K])
#if bpy.context.active_object["AFRAME_CUBEMAP"] is not None:
# box.label(text="AFRAME_CUBEMAP")
row = layout.row(align=True)
row.operator('aframe.export', text='Export A-Frame Project')
row = layout.row(align=True)
serve_label = "Stop Serving" if Server.instance else "Start Serving"
row.operator('aframe.serve', text=serve_label)
row = layout.row(align=True)
if Server.instance:
row.operator("wm.url_open", text="Open Preview").url = f'http://localhost:{PORT}'
row = layout.row(align=True)
row.label(text=scene.s_output, icon='INFO')
class AframeClean_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.clean"
bl_label = "Clean"
bl_description = "Clean"
def execute(self, content):
# TODO checkout is add-on is present
bpy.ops.tlm.clean_lightmaps("INVOKE_DEFAULT")
print("cleaning baked lightmaps")
return {'FINISHED'}
class AframeBake_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.bake"
bl_label = "Bake"
bl_description = "Bake"
def execute(self, content):
# TODO checkout is add-on is present
bpy.ops.tlm.build_lightmaps("INVOKE_DEFAULT")
print("internal bake")
return {'FINISHED'}
class AframeClearAsset_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.clear_asset_dir"
bl_label = "Crear Asset Directory"
bl_description = "Crear Asset Directory"
def execute(self, content):
scene = content.scene
DEST_RES = os.path.join ( scene.export_path, scene.s_project_name )
# Clear existing "assests" directory
assets_dir = os.path.join ( DEST_RES, PATH_ASSETS )
if os.path.exists( assets_dir ):
shutil.rmtree( assets_dir )
return {'FINISHED'}
class AframePrepare_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.prepare"
bl_label = "Prepare for Ligthmapper"
bl_description = "Prepare Lightmapper"
def execute(self, content):
scene = content.scene
DEST_RES = os.path.join ( scene.export_path, scene.s_project_name )
bpy.context.scene.TLM_SceneProperties.tlm_mode = 'GPU'
view_layer = bpy.context.view_layer
obj_active = view_layer.objects.active
selection = bpy.context.selected_objects
bpy.ops.object.select_all(action='SELECT')
bpy.context.view_layer.objects.active = obj_active
for obj in selection:
obj.select_set(True)
# some exporters only use the active object
view_layer.objects.active = obj
bpy.context.object.TLM_ObjectProperties.tlm_mesh_lightmap_use = True
bpy.context.object.TLM_ObjectProperties.tlm_mesh_lightmap_resolution = '256'
return {'FINISHED'}
class AframeClear_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.delete_lightmap"
bl_label = "Delete generated lightmaps"
bl_description = "Delete Lightmaps"
def execute(self, content):
scene = content.scene
DEST_RES = os.path.join ( scene.export_path, scene.s_project_name )
# delete all _baked textures
images = bpy.data.images
for img in images:
if "_baked" in img.name:
print("[CLEAR] delete image "+img.name)
bpy.data.images.remove(img)
#for material in bpy.data.materials:
# material.user_clear()
# bpy.data.materials.remove(material)
for filename in os.listdir(os.path.join ( DEST_RES, PATH_LIGHTMAPS)):
os.remove(os.path.join ( DEST_RES, PATH_LIGHTMAPS) + filename)
#if os.path.exists(os.path.join(DEST_RES, PATH_LIGHTMAPS)):
# shutil.rmtree(os.path.join(DEST_RES,PATH_LIGHTMAPS))
#bpy.ops.tlm.build_lightmaps()
return {'FINISHED'}
class AframeSavelm_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.savelm"
bl_label = "Save lightmaps"
bl_description = "Save Lightmaps"
def execute(self, content):
images = bpy.data.images
scene = content.scene
original_format = scene.render.image_settings.file_format
settings = scene.render.image_settings
settings.file_format = 'PNG'
DEST_RES = os.path.join ( scene.export_path, scene.s_project_name )
for img in images:
if "_baked" in img.name and img.has_data:
ext = ".png"
#ext = "."+img.file_format
#img.filepath = image_dir_path+img.name+ext
#print( os.path.join ( DEST_RES, PATH_LIGHTMAPS, img.name+ext ) )
img.file_format = 'PNG'
img.save_render(os.path.join ( DEST_RES, PATH_LIGHTMAPS, img.name+ext ) )
print("[SAVE LIGHTMAPS] Save image "+img.name)
settings.file_format = original_format
return {'FINISHED'}
class AframeLoadlm_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.loadlm"
bl_label = "load lightmaps"
bl_description = "Load Lightmaps"
def execute(self, content):
scene = content.scene
DEST_RES = os.path.join ( scene.export_path, scene.s_project_name )
# delete all _baked textures
images = bpy.data.images
for img in images:
if "_baked" in img.name:
print("delete: "+img.name)
bpy.data.images.remove(img)
for filename in os.listdir(os.path.join ( DEST_RES, PATH_LIGHTMAPS)):
bpy.data.images.load(os.path.join ( DEST_RES, PATH_LIGHTMAPS) + filename)
return {'FINISHED'}
class AframeServe_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.serve"
bl_label = "Serve Aframe Preview"
bl_description = "Serve AFrame"
def execute(self, content):
if (Server.instance):
Server.instance.stop()
Server.instance = None
return {'FINISHED'}
scene = content.scene
Server.instance = Server()
Server.instance.set_folder(os.path.join ( scene.export_path, scene.s_project_name ))
Server.instance.start()
return {'FINISHED'}
class AframeExport_OT_Operator(bpy.types.Operator):
bl_idname = "aframe.export"
bl_label = "Export to Aframe Project"
bl_description = "Export AFrame"
def execute(self, content):
assets = []
entities = []
lights = []
print("[AFRAME EXPORTER] Starting Exporting Project.....................................")
scene = content.scene
scene.s_output = "exporting..."
script_file = os.path.realpath(__file__)
#print("script_file dir = "+script_file)
directory = os.path.dirname(script_file)
# Destination base path
DEST_RES = os.path.join ( scene.export_path, scene.s_project_name )
if __name__ == "__main__":
#print("inside blend file")
#print(os.path.dirname(directory))
directory = os.path.dirname(directory)
print("[AFRAME EXPORTER] Target Output Directory = "+directory)
ALL_PATHS = [ ".", PATH_ASSETS, PATH_RESOURCES, PATH_MEDIA, PATH_ENVIRONMENT, PATH_JAVASCRIPT, PATH_LIGHTMAPS ]
for p in ALL_PATHS:
dp = os.path.join ( DEST_RES, p )
print ( "--- DEST [%s] [%s] {%s}" % ( DEST_RES, dp, p ) )
os.makedirs ( dp, exist_ok=True )
#check if addon or script for correct path
_resources = [
[ ".", "favicon.ico", True ],
[ ".", "style.css" , True],
[ ".", "start_web_server.py" , False],
[ PATH_RESOURCES, "sky.jpg", False ],
[ PATH_RESOURCES, "play.png", False ],
[ PATH_RESOURCES, "pause.png", False],
[ PATH_RESOURCES, "play-skip-back.png", False],
[ PATH_RESOURCES, "mute.png",False ],
[ PATH_RESOURCES, "volume-low.png",False ],
[ PATH_RESOURCES, "volume-high.png",False ],
[ PATH_MEDIA, "image1.png",False ],
[ PATH_MEDIA, "image2.png",False ],
[ PATH_JAVASCRIPT, "webxr.js", True ],
[ PATH_JAVASCRIPT, "joystick.js", True ],
[ PATH_JAVASCRIPT, "camera-cube-env.js", True ],
[ PATH_ENVIRONMENT, "negx.jpg", True ],
[ PATH_ENVIRONMENT, "negy.jpg", True ],
[ PATH_ENVIRONMENT, "negz.jpg", True ],
[ PATH_ENVIRONMENT, "posx.jpg", True ],
[ PATH_ENVIRONMENT, "posy.jpg", True ],
[ PATH_ENVIRONMENT, "posz.jpg", True ],
]
SRC_RES = os.path.join ( directory, PATH_RESOURCES )
for dest_path, fname, overwrite in _resources:
if overwrite:
shutil.copyfile ( os.path.join ( SRC_RES, fname ), os.path.join ( DEST_RES, dest_path, fname ) )
else:
if not os.path.exists(os.path.join ( DEST_RES, dest_path, fname )):
shutil.copyfile ( os.path.join ( SRC_RES, fname ), os.path.join ( DEST_RES, dest_path, fname ) )
# Loop 3D entities
exclusion_obj_types = ['CAMERA','LAMP','ARMATURE']
exported_obj = 0
videocount=0
imagecount=0
scalefactor = 2
lightmap_files = os.listdir(os.path.join ( DEST_RES, PATH_LIGHTMAPS))
for file in lightmap_files:
print("[LIGHTMAP] Found Lightmap file: "+file)
# ONE SINGLE MESH
# Note: with a single mesh you can't add interactions
if scene.b_export_single_model:
print("[AFRAME EXPORTER] Exporting one single global mesh")
if scene.b_cast_shadows:
single_cast_shadows = "true"
else:
single_cast_shadows = "false"
entities.append('\n\t\t\t<a-entity id="#MainMesh" gltf-model="#MainMesh" scale="1 1 1" visible="true" shadow="cast: '+single_cast_shadows+'"></a-entity>')
assets.append('\n\t\t\t\t<a-asset-item id="MainMesh" src="./assets/MainMesh.gltf'+'"></a-asset-item>')
bpy.ops.object.select_all(action='SELECT')
filename = os.path.join ( DEST_RES, PATH_ASSETS, "MainMesh" ) # + '.glft' )
# bpy.ops.export_scene.gltf(filepath=filename, export_format='GLTF_EMBEDDED', use_selection=True)
# obj.select_set(state=True)
bpy.ops.export_scene.gltf(filepath=filename, export_format='GLTF_EMBEDDED', use_selection=True, export_texcoords = True, export_normals = True, export_draco_mesh_compression_enable = False, export_draco_mesh_compression_level = 6, export_draco_position_quantization = 14, export_draco_normal_quantization = 10, export_draco_texcoord_quantization = 12, export_draco_generic_quantization = 12,export_tangents = True, export_materials = 'EXPORT', export_colors = True, export_extras = True, export_yup = True, export_apply = True, export_animations = True, export_frame_range = True, export_frame_step = 1, export_force_sampling = True)
bpy.ops.object.select_all(action='DESELECT')
else:
# MULTI MESH EXPORTING
for obj in bpy.data.objects:
if obj.type not in exclusion_obj_types:
print("[AFRAME EXPORTER] loop object "+ obj.name)
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(state=True)
bpy.context.view_layer.objects.active = obj
#bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
location = obj.location.copy()
rotation = obj.rotation_euler.copy()
bpy.ops.object.location_clear()
actualposition = str(location.x)+" "+str(location.z)+" "+str(-location.y)
actualscale = str(scalefactor*bpy.data.objects[obj.name].scale.x)+" "+str(scalefactor*bpy.data.objects[obj.name].scale.y)+" "+str(scalefactor*bpy.data.objects[obj.name].scale.z)
#pi = 22.0/7.0
#actualrotation = str(((bpy.data.objects[obj.name].rotation_euler.x) / (2 * pi) * 360) - 90) +" " + str(((bpy.data.objects[obj.name].rotation_euler.z) / (2 * pi) * 360)-0) + " " + str(((bpy.data.objects[obj.name].rotation_euler.y) / (2 * pi) * 360)+90)
#actualrotation = str(bpy.data.objects[obj.name].rotation_euler.x) +" " + str(bpy.data.objects[obj.name].rotation_euler.z)+ " " + str(bpy.data.objects[obj.name].rotation_euler.y)
#actualrotation = str(math.degrees(-89.99+bpy.data.objects[obj.name].rotation_euler.x)) +" " + str(90+math.degrees(bpy.data.objects[obj.name].rotation_euler.y))+ " " + str(-90+math.degrees(bpy.data.objects[obj.name].rotation_euler.z))
#actualrotation = str(math.degrees(rotation.x))+" "+str(math.degrees(rotation.z))+" "+str(math.degrees(-rotation.y))
actualrotation = "0 "+str(math.degrees(rotation.z))+" 0"
# custom aframe code read from CUSTOM PROPERTIES
reflections = ""
animation = ""
link = ""
baked = ""
custom = ""
toggle = ""
video = False
image = False
tag = "entity"
gltf_model = 'gltf-model="#'+obj.name+'"'
# export gltf
# print(obj.type)
if obj.type == 'MESH' or obj.type == 'EMPTY':
if obj.type == 'EMPTY':
gltf_model = ''
#print(obj.name,"custom properties:\n********************")
for K in obj.keys():
#print(K , "-" , obj[K], "\n" )
#print(K , "=" , obj[K])
if K not in '_RNA_UI':
#print( "\n", K , "-" , obj[K], "\n" )
if K == "AFRAME_CUBEMAP" and scene.b_cubemap:
if scene.b_camera_cube:
reflections = ' geometry="" camera-cube-env="distance: 500; resolution: 512; repeat: true; interval: 400" '
else:
reflections = ' geometry="" cube-env-map="path: '+scene.s_cubemap_path+'; extension: '+scene.s_cubemap_ext+'; reflectivity: 0.99;" '
elif K == "AFRAME_ANIMATION":
animation = ' animation= "'+obj[K]+'" '
elif K == "AFRAME_HTTP_LINK":
#link = ' link="href: '+obj[K]+'" class="clickable" '
link = ' link-handler="target: '+obj[K]+'" class="clickable" '
elif K == "AFRAME_VIDEO":
#print("--------------- pos " + actualposition)
#print("--------------- rot " + actualrotation)
#print("--------------- scale " + actualscale)
#filename = os.path.join ( DEST_RES, PATH_ASSETS, obj.name ) # + '.glft' )
#bpy.ops.export_scene.gltf(filepath=filename, export_format='GLTF_EMBEDDED', use_selection=True)
#assets.append('\n\t\t\t\t<a-asset-item id="'+obj.name+'" src="./assets/'+obj.name + '.gltf'+'"></a-asset-item>')
assets.append('\n\t\t\t\t<video id="video_'+str(videocount)+'" loop="true" autoplay="true" src="./media/'+obj[K]+'"></video>')
entities.append('\n\t\t\t<a-video id="#v_'+str(videocount)+'" src="#video_'+str(videocount)+'" width="1" height="1" scale="'+actualscale+'" position="'+actualposition+'" rotation="'+actualrotation+'" visible="true" shadow="cast: false" '+animation+link+'></a-video>')
#entities.append('\n\t\t\t<a-video id="#v_'+str(videocount)+'" src="#video_'+str(videocount)+'" width="'+str(bpy.data.objects[obj.name].scale.x)+'" height="'+str(bpy.data.objects[obj.name].scale.y)+'" scale="1 1 1" position="'+actualposition+'" rotation="'+actualrotation+'" visible="true" shadow="cast: false" '+animation+link+'></a-video>')
#entities.append('\n\t\t\t<a-entity id="#'+obj.name+'" gltf-model="#'+obj.name+'" material="src: #video_'+str(videocount)+'" scale="'+actualscale+'" rotation="'+actualrotation+'" position="'+actualposition+'"></a-entity>')
video = True
videocount = videocount +1
elif K == "AFRAME_IMAGES":
#print(".....images")
image = True
imagecount = imagecount +1
#load K
#json_images = '{"1": "image1.jpg", "2": "image2.jpg"}'
json_images = obj[K]
json_dictionary = json.loads(json_images)
for key in json_dictionary:
#print(key, ":", json_dictionary[key])
assets.append('\n\t\t\t\t<img id="image_'+key+'" src="./media/'+json_dictionary[key]+'"></img>')
entities.append('\n\t\t\t<a-image images-handler id="#i_'+str(imagecount)+'" src="#image_'+key+'" class="clickable" width="1" height="1" scale="'+actualscale+'" position="'+actualposition+'" rotation="'+actualrotation+'" visible="true" shadow="cast: false"></a-image>')
elif K == "AFRAME_SHOW_HIDE_OBJECT":
toggle = ' toggle-handler="target: #'+obj[K]+';" class="clickable" '
elif K == "AFRAME_TAG":
tag = obj[K]
elif K == "AFRAME_NOGLTF":
gltf_model = ""
elif K.startswith('AFRAME_'):
attr = K.split("AFRAME_")[1].lower()
custom = custom+' '+attr+'="'+str(obj[K])+'"'
#print("********************")
if video == False and image == False:
# check if baked texture is present on filesystem
#images = bpy.data.images
#for img in images:
# if obj.name+"_baked" in img.name and img.has_data:
# print("ok")
# baked = 'light-map-geometry="path: lightmaps/'+img.name+'"'
print("[LIGHTMAP] Searching Lightmap for object ["+obj.name+"_baked"+"]")
for file in lightmap_files:
if obj.name+"_baked" in file:
print("[LIGHTMAP] Found lightmap: "+file)
baked = 'light-map-geometry="path: lightmaps/'+file+'; intensity: '+str(scene.f_lightMapIntensity)+'"'
filename = os.path.join ( DEST_RES, PATH_ASSETS, obj.name ) # + '.glft' )
#bpy.ops.export_scene.gltf(filepath=filename, export_format='GLTF_EMBEDDED', use_selection=True)
bpy.ops.export_scene.gltf(filepath=filename, export_format='GLTF_EMBEDDED', use_selection=True, export_texcoords = True, export_normals = True, export_draco_mesh_compression_enable = False, export_draco_mesh_compression_level = 6, export_draco_position_quantization = 14, export_draco_normal_quantization = 10, export_draco_texcoord_quantization = 12, export_draco_generic_quantization = 12,export_tangents = True, export_materials = 'EXPORT', export_colors = True, export_extras = True, export_yup = True, export_apply = True, export_animations = True, export_frame_range = True, export_frame_step = 1, export_force_sampling = True)
assets.append('\n\t\t\t\t<a-asset-item id="'+obj.name+'" src="./assets/'+obj.name + '.gltf'+'"></a-asset-item>')
if scene.b_cast_shadows:
entities.append('\n\t\t\t<a-'+tag+' id="#'+obj.name+'" '+gltf_model+' scale="1 1 1" position="'+actualposition+'" visible="true" shadow="cast: true" '+reflections+animation+link+custom+toggle+'></a-'+tag+'>')
else:
entities.append('\n\t\t\t<a-'+tag+' id="#'+obj.name+'" '+gltf_model+' '+baked+' scale="1 1 1" position="'+actualposition+'" visible="true" shadow="cast: false" '+reflections+animation+link+custom+toggle+'></a-'+tag+'>')
# deselect object
obj.location = location
obj.select_set(state=False)
exported_obj+=1
# Loop the Lamps
print('[LAMPS] Searching for lamps in scene')
lamp_types = ['LIGHT']
blender_lights = []
for obj in bpy.data.objects:
# print(obj.name, ' = ', obj.type)
if obj.type in lamp_types:
#print(obj.name, obj.data.type, obj.data.color, obj.data.distance, obj.data.cutoff_distance, str(obj.location.x)+" "+str(obj.location.z)+" "+str(-obj.location.y))
distance = str(obj.data.distance)
hex_color = to_hex(obj.data.color)
#print("color = "+hex_color)
#default light type
light_type = "directional"
if obj.data.type == "POINT":
light_type = "point"
elif obj.data.type == "SUN":
light_type = "directional"
elif obj.data.type == "SPOT":
light_type = "spot"
light_position = str(obj.location.x)+" "+str(obj.location.z)+" "+str(-obj.location.y)
cutoff_distance = str(obj.data.cutoff_distance)
intensity = str(1.0)
if scene.b_cast_shadows:
cast_shadows = "true"
else:
cast_shadows = "false"
blender_lights.append('\n\t\t\t<a-entity position="'+light_position+'" light="castShadow:'+str(cast_shadows)+'; color:'+hex_color+'; distance:'+cutoff_distance+'; type:'+light_type+'; intensity:'+intensity+'; shadowBias: -0.001; shadowCameraFar: 501.02; shadowCameraBottom: 12; shadowCameraFov: 101.79; shadowCameraNear: 0; shadowCameraTop: -5; shadowCameraRight: 10; shadowCameraLeft: -10; shadowRadius: 2;"></a-entity>')
#print(blender_lights)
# Loop the Lamps
print("[AFRAME EXPORTER] Completed Exporting Project.....................................")
bpy.ops.object.select_all(action='DESELECT')
# Templating ------------------------------
#print(assets)
all_assets = ""
for x in assets:
all_assets += x
all_entities = ""
for y in entities:
all_entities += y
# scene
if scene.b_stats:
showstats = "stats"
else:
showstats = ""
# joystick
if scene.b_joystick:
showjoystick = "joystick"
else:
showjoystick = ""
if scene.b_raycast:
raycaster='raycaster = "far: '+str(scene.f_raycast_length)+'; interval: '+str(scene.f_raycast_interval)+'; objects: .clickable,.links"'
else:
raycaster=""
#vr_controllers
if scene.b_vr_controllers:
showvr_controllers = '<a-entity id="leftHand" oculus-touch-controls="hand: left" vive-controls="hand: left"></a-entity>\n\t\t\t\t\t<a-entity id="rightHand" laser-controls oculus-touch-controls="hand: right" vive-controls="hand: right" '+raycaster+'></a-entity>'
else:
showvr_controllers = ""
#shadows
if scene.b_cast_shadows:
showcast_shadows = "true"
template_render_shadows = 'shadow="type: pcfsoft; autoUpdate: true;"'
else:
showcast_shadows = "false"
template_render_shadows = 'shadow="type: basic; autoUpdate: false;"'
# Sky
if scene.b_show_env_sky:
show_env_sky = '<a-sky src="#sky" material="" geometry="" rotation="0 90 0"></a-sky>'
else:
show_env_sky = '<a-sky color="#ECECEC"></a-sky>'
# if use bake, the light should have intensity near zero
if scene.b_use_lightmapper:
light_directional_intensity = "0"
light_ambient_intensity = "0.1"
else:
light_directional_intensity = "1.0"
light_ambient_intensity = "1.0"
if scene.b_use_default_lights:
final_lights = '<a-entity light="intensity: '+ light_directional_intensity+'; castShadow: '+showcast_shadows+'; shadowBias: -0.001; shadowCameraFar: 501.02; shadowCameraBottom: 12; shadowCameraFov: 101.79; shadowCameraNear: 0; shadowCameraTop: -5; shadowCameraRight: 10; shadowCameraLeft: -10; shadowRadius: 2" position="1.36586 7.17965 1"></a-entity>\n\t\t\t<a-entity light="type: ambient; intensity: '+light_ambient_intensity+'"></a-entity>'
#print("final lights="+final_lights)
else:
templights = ""
for x in blender_lights:
templights += x
final_lights = templights
#Renderer
showrenderer = 'renderer="antialias: '+str(scene.b_aa).lower()+'; colorManagement: '+str(scene.b_colorManagement).lower()+'; physicallyCorrectLights: '+str(scene.b_physicallyCorrectLights).lower()+';"'
default_template()
t = Template( bpy.data.texts['index.html'].as_string() )
s = t.substitute(
asset=all_assets,
entity=all_entities,
stats=showstats,
aframe_version=scene.s_aframe_version,
joystick=showjoystick,
vr_controllers=showvr_controllers,
cast_shadows=showcast_shadows,
player_height=scene.f_player_height,
player_speed=scene.f_player_speed,
show_raycast=raycaster,
sky=show_env_sky,
render_shadows=template_render_shadows,
lights=final_lights,
renderer=showrenderer)
#print(s)
# Saving the main INDEX FILE
with open( os.path.join ( DEST_RES, PATH_INDEX ), "w") as file:
file.write(s)
scene.s_output = str(exported_obj)+" meshes exported"
#self.report({'INFO'}, str(exported_obj)+" meshes exported")
return {'FINISHED'}
# ------------------------------------------- REGISTER / UNREGISTER
_props = [
("str", "s_aframe_version", "A-Frame version", "A-Frame version", "1.2.0" ),
("bool", "b_stats", "Show Stats", "Enable rendering stats in game" ),
("bool", "b_vr_controllers", "Enable VR Controllers (HTC,Quest)", "Enable HTC/Quest Controllers in game", True ),
("bool", "b_hands", "Use Hands Models", "Use hands models instead of controllers", True ),
("bool", "b_joystick", "Show Joystick", "Add a joystick on screen" ),
("bool", "b_cubemap", "Cube Env Map", "Enable Cube Map component" ),
("str", "s_cubemap_path", "Path", "Cube Env Path", "/env/" ),
("bool", "b_cubemap_background", "Enable Background", "Enable Cube Map Background" ),
("str", "s_cubemap_ext", "Ext", "Image file extension", "jpg" ),
("bool", "b_blender_lights", "Export Blender Lights", "Export Blenedr Lights or use Aframe default ones" ),
("bool", "b_cast_shadows", "Cast Shadows", "Cast and Receive Shadows" ),
("bool", "b_use_default_lights", "Don't export Blender lights", "Use Default Lights - don't export blender lights" ),
("bool", "b_lightmaps", "Use Lightmaps as Occlusion (GlTF Settings)", "GLTF Models don\'t have lightmaps: turn on this option will save lightmaps to Ambient Occlusion in the GLTF models" ),
("float", "f_player_speed", "Player Speed", "Player Speed", 0.1 ),
("float", "f_raycast_length", "Raycast Length","Raycast lenght to interact with objects", 10.0 ),
("float", "f_raycast_interval", "Raycast Interval","Raycast Interval to interact with objects", 1500.0 ),
("str", "export_path", "Export To","Path to the folder containing the files to import", "C:/Temp/", 'FILE_PATH'),
("bool", "b_export_single_model", "Export to a single glTF model","Export to a single glTF model" ),
("str", "s_project_name", "Name", "Project's name","aframe-prj"),
("str", "s_output", "output","output export","output"),
("bool", "b_use_lightmapper", "Use Lightmapper Add-on","Use Lightmapper for baking" ),
("bool", "b_camera_cube", "Camera Cube Env","Enable Camera Cube Env component"),
("float", "f_player_height", "Player Height","Player Height", 1.7),
("bool", "b_raycast", "Enable Raycast","Enable Raycast"),
("bool", "b_show_env_sky", "Show Environment Sky","Show Environment Sky"),
("bool", "b_settings", "A-Frame settings","b_settings"),
("bool", "b_player", "Player settings","b_player"),
("bool", "b_interactive", "Interactive","b_interactive"),
("bool", "b_export", "Exporter settings","b_export"),
("bool", "b_bake", "Bake settings","b_bake"),
("bool", "b_bake_lightmap", "Bake settings","b_bake_lightmap"),
("float", "f_lightMapIntensity", "LightMap Intensity","LightMap Intensity", 2.0),
("str", "s_link", "Link Url", "Link Url" , "https://www.google.it/"),
("str", "s_video", "Video File Name", "Video File Name" , "video.mp4"),
("str", "s_showhide_object", "Show Hide Object", "Show Hide Object: insert object id \ne.g. Cube.001" , "Cube.001"),
("str", "s_toggle_object", "Toggle Objects", 'Insert n id objects in JSON format e.g.\n{"1": "Cube.001", "2": "Cube.002"}, "3": "Cube.003"}' , '{"1": "Cube.001", "2": "Cube.002"}'),
("bool", "b_renderer", "Renderer Settings","A-Frame Renderer Settings"),
("bool", "b_aa", "Antialiasing","Antialiasing"),
("bool", "b_colorManagement", "Color Management","ColorManagement"),
("bool", "b_physicallyCorrectLights", "Physically Correct Lights","PhysicallyCorrectLights"),
]
# CUSTOM PROPERTY OPERATORS
class DeleteProperty(bpy.types.Operator):
bl_idname = 'aframe.delete_property'
bl_label = 'Remove'
bl_description = 'Remove custom property from selected object'
targetproperty: bpy.props.StringProperty(name="targetproperty")
def execute(self, context):
try:
scene = context.scene
print("deleting:" , self.targetproperty)
del bpy.context.active_object[self.targetproperty]
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class ShowHideObject(bpy.types.Operator):
bl_idname = 'aframe.show_hide_object'
bl_label = 'Add Show Hide Object'
bl_description = 'Show and Hide object by clicking this entity'
def execute(self, context):
try:
scene = context.scene
bpy.context.active_object["AFRAME_SHOW_HIDE_OBJECT"] = scene.s_showhide_object
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class ToogleObjects(bpy.types.Operator):
bl_idname = 'aframe.toggle_object'
bl_label = 'Add Toggle Object'
bl_description = 'Add two toggle objects for selected object'
def execute(self, context):
try:
bpy.context.active_object["AFRAME_TOOGLE_OBJECT"] = '{"1": "id1", "2": "id2"}'
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class Images(bpy.types.Operator):
bl_idname = 'aframe.images'
bl_label = 'Add Toggle Images'
bl_description = 'Add two toggle images for selected object'
def execute(self, context):
try:
bpy.context.active_object["AFRAME_IMAGES"] = '{"1": "image1.png", "2": "image2.png"}'
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class Cubemap(bpy.types.Operator):
bl_idname = 'aframe.cubemap'
bl_label = 'Add Cubemap'
bl_description = 'Add a cubemap for selected object to make it transparent'
def execute(self, context):
try:
bpy.context.active_object["AFRAME_CUBEMAP"] = "1"
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class Rotation360(bpy.types.Operator):
bl_idname = 'aframe.rotation360'
bl_label = 'Add Rotation on Z'
bl_description = 'Rotation Object 360 on Z axis'
def execute(self, context):
try:
bpy.context.active_object["AFRAME_ANIMATION"] = "property: rotation; to: 0 360 0; loop: true; dur: 10000"
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class LinkUrl(bpy.types.Operator):
bl_idname = 'aframe.linkurl'
bl_label = 'Add Link Web'
bl_description = 'Insert URL WEB'
def execute(self, context):
try:
scene = context.scene
bpy.context.active_object["AFRAME_HTTP_LINK"] = scene.s_link
except Exception as e:
bpy.ops.wm.popuperror('INVOKE_DEFAULT', e = str(e))
return {'FINISHED'}
class VideoPlay(bpy.types.Operator):
bl_idname = 'aframe.videoplay'
bl_label = 'Add Video'