# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
        "name": "vrToolsAframe",
        "author": "Olivier Borne",
        "version": 23,
        "blender": (3, 1, 0),
        "location": "View3D > Sidebar",
        "description": "Tools for VR in a-Frame - window 10",
        "category": "Object"
}

import bpy
import os, shutil
import mathutils
import glob
from bpy.props import (StringProperty,
                       BoolProperty,
                       IntProperty,
                       FloatProperty,
                       EnumProperty,
                       PointerProperty,
                       )
from bpy.types import (Panel,
                       Operator,
                       PropertyGroup,
                       )
import os.path, os

#OPTION THEATRE DE RUE   
bpy.types.Scene.my_prop = BoolProperty(
                name="Street Theater",
                description="Choix du lieu"
                )

# Dialogue Box
class MySettings(PropertyGroup):
    #pour le nom du projet
    my_string : StringProperty(
        name="Project",
        description="Project name",
        default="",
        maxlen=1024,
        )
    
    #pour le fichier son
    my_string1 = StringProperty(
        name="Sound",
        description="Entrez le fichier son",
        default="",
        maxlen=1024,
        )
    
    def execute(self, context):
        scene = context.scene
        mytool = scene.my_tool

        
        
        print("string value:", mytool.my_string)
        print("string value:", mytool.my_string1)

        return {'FINISHED'}


#CREATION DES DOSSIERS D'EXPORTATION
class CREATE_OT_createFolder(bpy.types.Operator):
    bl_idname = "object.createfolder"
    bl_label = "New Folders"
    bl_description = "Create Folder for the project in Folders work and viewing\nwork\n..projet\n....cycles\n....internal\n....texture\n......origine\n......bake\nviewing\n..projet\n....smartphone\n....Gear\n....casque\n....models\n....teleport\n......smartphone"

    def execute(self, context):
        #Cree les dossiers de travail: work
        dossier = bpy.context.scene.directory
        projet = bpy.context.scene.my_tool.my_string
        newpath = r'' + (dossier) + '\\work\\' + (projet) + '\\cycles'

        if not os.path.exists(newpath):
            os.makedirs(newpath)
        newpath = r'' + (dossier) + '\\work\\' + (projet) + '\\texture\\bake' 
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        newpath = r'' + (dossier) + '\\work\\' + (projet) + '\\texture\\origine' 
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        #Cree les dossiers de visionnage : viewing
        #Pour les casques 6DOF
        newpath = r'' + (dossier) + '\\viewing\\'+ projet + '\\casque'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        #Pour le webXR
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\webxr'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        #Pour les computer
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\ordinateur'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
            
            
        #Pour les smartphone 
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\smartphone'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        #Pour les models des projets
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
            
        #Pour les models en gltf (webxr)des projets
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\modelsXr'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
            
        #Pour les models des liens des ordinateurs
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\modelsForlinkOrdi'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        #Pour les teleport des projets
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
            
        #Pour les teleport des smartphone
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleportsmartphone'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        #Pour les lien en 6DOF et 3DOF
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\link'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
            
        #Pour les lien en 6DOF et 3DOF
        newpath = r'' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\linkOrdinateur'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        
        return {'FINISHED'}



#CREATE UVBAKE
#CREE LES UVBAKE
class CREATE_OT_uvBake(Operator):
    bl_idname = "object.uvbake"
    bl_label = "Create uvmap with name: uvBake"
    bl_description = "For each object selected: creation of an uv map called uvBake "

    def execute(self, context):
        selUv = bpy.context.object.data
        for obj in bpy.context.selected_objects:
            obj.hide_render = False
            newUv = obj.data
            uv_layers = obj.data.uv_layers
            if obj.type == 'MESH':
                obj.select_set(True)
                newUv.uv_layers.new(name="uvBake")
                try:
                    uv_layers.remove(uv_layers['uvBake.001'])
                except  KeyError:
                    pass
                           
                for uvmap in  obj.data.uv_layers :
                    if uvmap.name == 'uvBake':
                        selUv.uv_layers.active_index = 0
                
        return {'FINISHED'}

   

#DEPLIAGE UVMAP CALL UV UVbAKE
#DEPLIAGE DES CARTES UV UVbAKE
class DEPLI_OT_depliUvBake(Operator):
    bl_idname = "object.depliuvbake"
    bl_label = "Unwrap uvBake"
    bl_description = "For each object select : unwrap all uvMap called uvBake"

    def execute(self, context):
        if bpy.context.selected_objects != []:
            for obj in bpy.context.selected_objects:
                bpy.ops.object.select_all(action='DESELECT')
                if obj.type == 'MESH':
                    try:
                        bpy.context.view_layer.objects.active = obj
                        obj.select_set(True)
                        bpy.ops.object.editmode_toggle() 
                        bpy.ops.mesh.select_all(action='SELECT')
                        bpy.context.object.data.uv_layers['uvBake'].active = True 
                        bpy.ops.uv.smart_project(angle_limit=1, island_margin=0.01, area_weight=0.00, correct_aspect=True, scale_to_bounds=False) 
                        bpy.ops.object.editmode_toggle()
                                        
                    except  KeyError:
                        def ShowMessageBox(message = "", title = "You don't have uvBake on your object", icon = 'ERROR'):

                            def draw(self, context):
                                self.layout.label(message)                                
                            bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

                        bpy.ops.object.editmode_toggle()
                        ShowMessageBox("You must create new uvBake") 
                  
        return {'FINISHED'}



#CREATING IMAGES 512 pixels x 512 pixels FOR BAKING
#CREATION DES IMAGES 512 pixels x 512 pixels POUR LE BAKING
class CREA_OT_createImageBakeLow(Operator):
    bl_idname = "object.createimagebakelow"
    bl_label = "New image 512x512"
    bl_description = "For all object selected : creating a 512 pixel x 512 pixel jpg image of the same name as the selected object.\nThis image is saved in the folder work> project> texture> bake"

    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                img = obj.name
                for block in bpy.data.images: 
                    if block.name == img:
                        bpy.data.images.remove(block)
                
                image = bpy.data.images.new(img, alpha=True, width=512, height=512)
             
                image.filepath_raw = "" + (dossier) + '\\work\\' + (projet) + '\\texture\\bake\\' + img + ".jpg"
                image.file_format = 'JPEG'
                image.save()
                for block in bpy.data.images:
                    if block.users == 0 and block.name == img + '.001':
                        bpy.data.images.remove(block)
                                      
        return {'FINISHED'}



#CREATING IMAGES 1024 pixels x 1024 pixels FOR BAKING
#CREATION DES IMAGES 1024 pixels x 1024 pixels POUR LE BAKING
class CREA_OT_createImageBakeMedium(Operator):
    bl_idname = "object.createimagebakemedium"
    bl_label = "New image 1024x1024"
    bl_description = "For all object selected : creating a 1024 pixel x 1024 pixel jpg image of the same name as the selected object.\nThis image is saved in the folder work> project> texture> bake"
                  
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                img = obj.name
                for block in bpy.data.images: 
                    if block.name == img:
                        bpy.data.images.remove(block)
                image = bpy.data.images.new(img, alpha=True, width=1024, height=1024)
             
                image.filepath_raw = "" + (dossier) + '\\work\\' + (projet) + '\\texture\\bake\\' + img + ".jpg"
                image.file_format = 'JPEG'
                image.save()
                for block in bpy.data.images:
                    if block.users == 0 and block.name == img + '.001':
                        bpy.data.images.remove(block) 
                  
        return {'FINISHED'}



#CREATING IMAGES 2048 pixels x 2048 pixels FOR BAKING
#CREATION DES IMAGES 2048 pixels x 2048  pixels POUR LE BAKING
class CREA_OT_createImageBakeHight(Operator):
    bl_idname = "object.createimagebakehight"
    bl_label = "New image 2048x2048"
    bl_description = "For all object selected : creating a 2048 pixel x 2048 pixel jpg image of the same name as the selected object.\nThis image is saved in the folder work> project> texture> bake"

    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                img = obj.name
                for block in bpy.data.images: 
                    if block.name == img:
                        bpy.data.images.remove(block)
                image = bpy.data.images.new(img, alpha=True, width=2048, height=2048)
             
                image.filepath_raw = "" + (dossier) + '\\work\\' + (projet) + '\\texture\\bake\\' + img + ".jpg"
                image.file_format = 'JPEG'
                image.save()
                for block in bpy.data.images:
                    if block.users == 0 and block.name == img + '.001':
                        bpy.data.images.remove(block) 
                  
        return {'FINISHED'}



#CREATION OF NODES IMAGES AND UVMAP FOR BAKING
#CREATION DES NODES IMAGES ET UVMAP POUR LE BAKING
class CREA_OT_createNodeBake(Operator):
    bl_idname = "object.createnodebake"
    bl_label = "New nodes"
    bl_description = "For all object selected and for each material of this object:\n creation of a texture image node with as input vector the creation of an uvmap node with uvBake coordinates"

    def execute(self, context):
        row1 =400
        col1 =500
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        path =  "" + (dossier) + "\\work\\" + (projet) + "\\texture\\bake\\" 
        a = bpy.context.object.data.uv_layers
        listeBake = [x.name for x in a]
        l=os.listdir(path)
        li = [x.split('.jpg')[-2] for x in l]
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                bpy.ops.object.make_single_user(type='SELECTED_OBJECTS', object=False, obdata=False, material=True)
                img = obj.name
                if img in li and 'uvBake' in listeBake:
                
                    for a in bpy.data.scenes[0].objects[obj.name].data.materials:
                                               
                        a.use_nodes=True
                  
                        TreeNodes = a.node_tree
                        links = TreeNodes.links                                                                        
                        for n in TreeNodes.nodes:
                            if n.name == "textureBake " + img or n.name == "uvBake " + img:
                                TreeNodes.nodes.remove(n)
                                                        
                        texEnter = TreeNodes.nodes.new('ShaderNodeTexImage')
                        texEnter.name = "textureBake " + img
                        texEnter.location = col1-1000, row1
                        texEnter.image = bpy.data.images[img]
                        TreeNodes.nodes.active = texEnter
                        
                        uvEnter = TreeNodes.nodes.new('ShaderNodeUVMap')
                        uvEnter.name = "uvBake " + img
                        uvEnter.location = col1-1200, row1
                                                
                        bpy.context.object.data.uv_layers['uvBake'].active = True
                        uvEnter.uv_map = 'uvBake'
                        links.new(uvEnter.outputs[0],texEnter.inputs[0])
                        
                else:  
                        def ShowMessageBoxNew(message = "", title = "You don't have image or uvMap called uvBake on your object", icon = 'ERROR'):

                            def draw(self, context):
                                self.layout.label(message)
                            bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

                        ShowMessageBoxNew("You must create Newimage and uvMap called uvBke on " + img)
                                                        
        return {'FINISHED'}         



#RUN BAKE FOR ALL SELECTED OBJECTS
#LANCE LE BAKE POUR TOUS LES OBJETS SELECTIONNES
class BAKE_OT_Baking(Operator):
    bl_idname = "object.baking"
    bl_label = "Run Texture Bake"
    bl_description = "For all selected object and for each material of this object : \nBake texture on previously saved images in the folders work>project>texture>bake "

    def execute(self, context):
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for obj in selection:
            if obj.type == 'MESH':
                img = obj.name
                try:
                    obj.select_set(True)
                    bpy.context.object.data.uv_layers['uvBake'].active=True
                    bak = obj.name
                    bpy.data.objects[bak].select_set(True)
                    
                    
                    bpy.ops.object.bake(type='COMBINED', margin=2)
                    bpy.data.images[bak].save()
                    obj.select_set(False)
                
                except  Exception:
                    def ShowMessageBoxNew(message = "", title = "You don't have uvBake on your object", icon = 'ERROR'):

                        def draw(self, context):
                            self.layout.label(message)
                        bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

                    ShowMessageBoxNew("You must create new uvBake " + img)
                    
                  
        return {'FINISHED'}


#MET LA TEXTURE BAKE SUR LES OBJETS
#PUT TEXTURE BAKE ON THE OBJETC
class NEWTEX_OT_putTexture(Operator):
    bl_idname = "object.puttexture"
    bl_label = "Texture Bake"
    bl_description = "Put the texture bake on the object"

   
            
    
    
    def execute(self, context):
        for new in bpy.context.selected_editable_objects:
            new.active_material_index = 0
            for i in range(len(new.material_slots)):
                bpy.ops.material.new()

       
        for slo in bpy.context.selected_editable_objects:
            slo.active_material_index = 0      
            mat = bpy.data.materials.new(name= "Basic")
            mat.use_nodes =True
            slo.active_material = mat
        
        
        
        
        row1 =400
        col1 =500
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        path =  "" + (dossier) + "\\work\\" + (projet) + "\\texture\\bake\\" 
        a = bpy.context.object.data.uv_layers
        listeBake = [x.name for x in a]
        l=os.listdir(path)
        li = [x.split('.jpg')[-2] for x in l]
        for obj in selection:
            img = obj.name
            
            if obj.type == 'MESH':
                obj.select_set(True)
                bpy.ops.object.make_single_user(type='SELECTED_OBJECTS', object=False, obdata=False, material=True)
                
                if img in li and 'uvBake' in listeBake:
                    
                    for a in bpy.data.scenes[0].objects[obj.name].data.materials:
                                               
                        a.use_nodes=True
                        
                        TreeNodes = a.node_tree
                        links = TreeNodes.links                                                                        
                        for n in TreeNodes.nodes:
                           TreeNodes.nodes.remove(n)
                                                        
                        
                        
                        texEnter = TreeNodes.nodes.new('ShaderNodeTexImage')
                        texEnter.name = "textureBake " + img
                        texEnter.location = col1-1000, row1
                        texEnter.image = bpy.data.images[img]
                        TreeNodes.nodes.active = texEnter
                        
                        uvEnter = TreeNodes.nodes.new('ShaderNodeUVMap')
                        uvEnter.name = "uvBake " + img
                        uvEnter.location = col1-1300, row1
                                                
                        bpy.context.object.data.uv_layers['uvBake'].active = True
                        uvEnter.uv_map = 'uvBake'
                        links.new(uvEnter.outputs[0],texEnter.inputs[0])
                        
                        princiEnter = TreeNodes.nodes.new('ShaderNodeBsdfPrincipled')
                        princiEnter.inputs[12].default_value = 0.
                        princiEnter.name = "principled " + img
                        princiEnter.location = col1-600, row1
                        TreeNodes.nodes.active = princiEnter
                        links.new(texEnter.outputs[0],princiEnter.inputs[0])
                        
                        outEnter = TreeNodes.nodes.new('ShaderNodeOutputMaterial')
                        outEnter.name = "outPut " + img
                        outEnter.location = col1-200, row1
                        TreeNodes.nodes.active = outEnter
                        links.new(princiEnter.outputs[0],outEnter.inputs[0])
                        
                else:  
                        def ShowMessageBoxNew(message = "", title = "You don't have image or uvMap called uvBake on your object", icon = 'ERROR'):

                            def draw(self, context):
                                self.layout.label(message)
                            bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

                        ShowMessageBoxNew("You must create Newimage and uvMap called uvBke on " + img)
                                                        
        return {'FINISHED'}         


#EXPORTED IN COLLADA THE OBJECTS IN THE FASHION RECORD
# EXPORTE EN COLLADA LES OBJETS DANS LE DOSSIER MODEL
class EXPORT_OT_ColladaExport(Operator):
    bl_idname = "object.colladaexport"
    bl_label = "Export ALL Collada "
    bl_description = "Export Collada selected object to the folder :\n viewing>project>models"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        path = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\models"
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for the_file in os.listdir(path):
            file_path = os.path.join(path, the_file)
            os.unlink(file_path)
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                bpy.ops.wm.collada_export(filepath=path + "/" + obj.name, check_existing=False, filter_blender=False, filter_image=False, filter_movie=False, filter_python=False, filter_font=False, filter_sound=False, filter_text=False, filter_btx=False, filter_collada=True, filter_folder=True, filemode=8, selected=True, active_uv_only=True)
                obj.select_set(False)
        return {'FINISHED'}      

#EXPORTED IN COLLADA ONLY ONE OBJECTS IN THE MODEL FOLDER
# EXPORTE EN COLLADA UN SEUL OBJET DANS LE DOSSIER MODEL
class EXPORTONLY_OT_ColladaOneExport(Operator):
    bl_idname = "object.colladaoneexport"
    bl_label = "Export Only one Collada "
    bl_description = "Export Collada selected object to the folder :\n viewing>project>models"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        path = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\models"
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                bpy.ops.wm.collada_export(filepath=path + "/" + obj.name, check_existing=False, filter_blender=False, filter_image=False, filter_movie=False, filter_python=False, filter_font=False, filter_sound=False, filter_text=False, filter_btx=False, filter_collada=True, filter_folder=True, filemode=8, selected=True, active_uv_only=True)
                obj.select_set(False)
        return {'FINISHED'}   




# EXPORT OBJECTS OBJ TO THE TELEPORT FILE OF EACH PROJECT
# EXPORTE EN OBJ LES OBJETS DANS LE DOSSIER TELEPORT DE CHAQUE PROJET
class TELEPORT_OT_TeleportExport(Operator):
    bl_idname = "object.teleportexport"
    bl_label = "Export Object Teleport .obj"
    bl_description = "Export teleport obj selected mesh  to directory"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        path = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleport"
        selection = bpy.context.selected_editable_objects
        bpy.ops.object.select_all(action='DESELECT')
        for the_file in os.listdir(path):
            file_path = os.path.join(path, the_file)
            os.unlink(file_path)
        for obj in selection:
            if obj.type == 'MESH':
                obj.select_set(True)
                
                #efface les materiaux pour les surfaces de teleportation
                #erase materials for the teleport
                obj.data.materials.clear()
                               
                bpy.ops.wm.obj_export(filepath=path + "/" + obj.name + ".obj", export_selected_objects=True)
                
        return {'FINISHED'}
 


#ECRIT LES LIGNES DE CODE POUR LA TELEPORTATION DES smartphone ET DES ORDINATEURS
class TELEPORTEMPTY_OT_Teleport(Operator):
    bl_idname = "object.teleport"
    bl_label = "Teleport Computer and smartphone"
    bl_description = "Write Empty for octoaedron in teleport smartphone folder"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_objects
        result = ""
        for ob in selection:
            z = str(-1 * round(ob.location[1],2))
            zeuler = str(-1 * round(ob.rotation_euler[1],2))
            result += " %s\n" % ("<!--" + ob.name + "--><a-octahedron color=\"red\" scale=\"0.1 0.3 0.1\" radius=\"1\" opacity=\"0.2\" position=\"" + str(round(ob.location[0],2)) + " " + str(round(ob.location[2],2)) + " " + z + "\" rotation=\"" + str(round(ob.rotation_euler[0],2)) + " " + str(round(ob.rotation_euler[2],2)) + " " + zeuler + "\"" + " warp-to></a-octahedron>")
        filename = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone", "teleport.txt")
        
        
        file = open(filename, "w", encoding="utf-8")
        file.write(result)
        file.close()
        return {'FINISHED'}


# WRITTEN THE CODE LINES FOR 6DOF HEADSETS FOR THE ROOM THEATER               
# ECRIT LES LIGNES DE CODE POUR LES CASQUES 6DOF POUR LE THEATRE EN SALLE
class SIXDOF_OT_Sixdof(bpy.types.Operator):
    bl_idname = "object.sixdof"
    bl_label = "Save html for heaset (webXR) Collada"
    bl_description = "Write file html for headset 6DOF"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        sound = bpy.context.scene.my_tool.my_string1
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        result4 = ""
        result5 = ""
        result6 = ""
        
        #filters DAE files for 6DOF headsets in the "models" folder of the project folder
        # filtre les fichiers DAE pour les casques 6DOF dans le dossier "models" du dossier du projet
        extentions = ["dae"]
        e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
        newList = []
        for word in e:
            if not word.startswith('._'):
                newList.append(word)
                f = newList
        
        # filters the obj files for 6DOF headsets in the "teleport" folder of the project folder
        # filtre les fichiers obj pour les casques 6DOF dans le dossier "teleport" du dossier du projet           
        newExtentions = ["obj"]
        g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
        teleportList = []
        
        
        

        # Start Html page                  
		# Début page Html
        a = '''<html>
	<head>
	<title>'''
        b = '''</title>
	<script src="../../components/script/aframe-v1.1.0.min.js"></script>
    <script src="../../components/script/collada-model.js"></script>
    <script src="../../components/script/aframe-extras.min.js"></script>
    <script src="../../components/script/aframe-teleport-controls.js"></script>
	<!--The MIT License (MIT) Copyright (c) 2017 Fernando Serrano; Copyright (c) 2016 Don McCurdy -->
	</head>
	<body>
	
	<a-scene antialias="true">
	<!--Déclaration-->
		<a-assets>
		<!--la salle-->
		<a-asset-item id="salle" src="../../components/theatre/models/salle.dae"></a-asset-item>
		<a-asset-item id="siege" src="../../components/theatre/models/siege.dae"></a-asset-item>
		<a-asset-item id="accotoir" src="../../components/theatre/models/accotoir.dae"></a-asset-item>
		<a-asset-item id="pendard" src="../../components/theatre/models/pendard.dae"></a-asset-item>
		<a-asset-item id="box" src="../../components/theatre/models/box.dae"></a-asset-item>
		<a-asset-item id="bloc" src="../../components/theatre/models/bloc.dae"></a-asset-item>
		<!--cloison1-->
		
		<!-- teleportation salle -->
		<a-asset-item id="salle_niv1_tele-obj" src="../../components/theatre/teleport/salle_niv1_tele.obj"></a-asset-item>
		<a-asset-item id="salle_niv2_tele-obj" src="../../components/theatre/teleport/salle_niv2_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv3_tele-obj" src="../../components/theatre/teleport/salle_niv3_tele.obj"></a-asset-item>
		<a-asset-item id="salle_niv4_tele-obj" src="../../components/theatre/teleport/salle_niv4_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv5_tele-obj" src="../../components/theatre/teleport/salle_niv5_tele.obj"></a-asset-item>
		<a-asset-item id="salle_niv6_tele-obj" src="../../components/theatre/teleport/salle_niv6_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv7_tele-obj" src="../../components/theatre/teleport/salle_niv7_tele.obj"></a-asset-item>
		<a-asset-item id="salle_niv8_tele-obj" src="../../components/theatre/teleport/salle_niv8_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv9_tele-obj" src="../../components/theatre/teleport/salle_niv9_tele.obj"></a-asset-item>
		<a-asset-item id="leurreRue-obj" src="../../components/theatre/teleport/leurreRue.obj"></a-asset-item>
		<!--le decor-->
		<!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
		
        # ecriture des assets
		# suite page html
        c = '''\n\n\t\t<!-- teleportation plateau -->
		<!--A REMPLACER CI-DESSOUS LISTE DES ASSETS DE TELEPORTATIONS GENERE PAR BLENDER-->'''
		
        # ecriture des teleportations
        ctele = '''<!--Link-->
		<img id="sortie" src="../../components/link/sortie.jpg">
		
    </a-assets>
	<!--Fin Déclaration-->
	
		<!--image de fond.-->
		<a-sky color="black"></a-sky>
	
	
	<!--placement--> 
		<!--La salle-->
        <!--sound-->'''
		#ecriture du son	

        cplace = '''\n\n\t\t<a-collada-model src="#salle" position="0 0 0"></a-collada-model>
		<a-entity position="0 0 0" scale="1 1 1" collada-model="src: #salle; colorCorrection: true"></a-entity>
        <a-entity position="0 0 0" scale="1 1 1" collada-model="src: #siege; colorCorrection: true"></a-entity>
        <a-entity position="0 0 0" scale="1 1 1" collada-model="src: #accotoir; colorCorrection: true"></a-entity>
        <a-entity position="0 0 0" scale="1 1 1" collada-model="src: #box; colorCorrection: true"></a-entity>
        <a-entity position="0 0 0" scale="1 1 1" collada-model="src: #bloc; colorCorrection: true"></a-entity>
		<!--Cloison-->
		
		<!-- teleportation salle -->
		<a-entity obj-model="obj: #salle_niv1_tele-obj;" material="opacity: 0" id="salle_niv1_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv2_tele-obj;" material="opacity: 0" id="salle_niv2_tele" position="" rotation="" scale="1"></a-entity>
		<a-entity obj-model="obj: #salle_niv3_tele-obj;" material="opacity: 0" id="salle_niv3_tele" position="" rotation="" scale="1"></a-entity>
		<a-entity obj-model="obj: #salle_niv4_tele-obj;" material="opacity: 0" id="salle_niv4_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv5_tele-obj;" material="opacity: 0" id="salle_niv5_tele" position="" rotation="" scale="1"></a-entity>
		<a-entity obj-model="obj: #salle_niv6_tele-obj;" material="opacity: 0" id="salle_niv6_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv7_tele-obj;" material="opacity: 0" id="salle_niv7_tele" position="" rotation="" scale="1"></a-entity>
		<a-entity obj-model="obj: #salle_niv8_tele-obj;" material="opacity: 0" id="salle_niv8_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv9_tele-obj;" material="opacity: 0" id="salle_niv9_tele" position="" rotation="" scale="1"></a-entity>
		<a-entity obj-model="obj: #leurreRue-obj;" material="opacity: 0" id="leurreRue" position="" rotation="" scale="1"></a-entity>
    
		<!--le decor-->
		<!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
        
        # placement writing
        # ecriture des placements
        
        d = '''\n\n\t\t<!-- teleportation plateau -->
		<!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS DES TELEPORTATIONS GENERE PAR BLENDER -->'''
		
        # writing teleport placements
        # ecriture des placements de teleportations
        dtele = '''\n\n\t<!--Fin placement-->
	
	<!--Links-->
	<!--menu-- <a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/mixedRea/menu.html" title="menu" image="#menu" position="7.6 2.91 6.22" rotation="0.0 90.0 0.0" scale="0.2 0.2 0.2"></a-link>-->
	 
	<!-- Player -->
	<!-- camera -->
	<a-entity id="cameraRig">
		<a-entity id="head" camera wasd-controls look-controls></a-entity>
		
		<!-- gachette -->
		<!--A REMPLACER CI-DESSOUS collisioEntity par les cibles de téléportation-->
		<a-entity
		teleport-controls="button: trigger; 
		cameraRig: #cameraRig; 
		teleportOrigin: #head;
		collisionEntities: '''
        
        #writing teleportation in the player
        #ecriture des teleportation dans le player
        dteleplace = '''#leurreRue, #salle_niv1_tele, #salle_niv2_tele, #salle_niv3_tele, #salle_niv4_tele, #salle_niv5_tele, #salle_niv6_tele, #salle_niv7_tele, #salle_niv8_tele, #salle_niv9_tele;
		curveLineWidth: 0.01;
		curveHitColor: #eaf1ea;
		hitCylinderColor: #eaf1ea; 
		hitCylinderHeight:0.1; 
		hitCylinderRadius: 0.1" 
	    hand-controls="hand: right; 
        handModelStyle: lowPoly; 
        color: #909c9f" 
		position="" rotation="" scale="" visible="" 
		vive-controls="" 
		oculus-touch-controls="" 
		windows-motion-controls="" 
        oculus-go-controls="hand: right"
        gearvr-controls="hand: right"></a-entity>
		<a-entity id="rightHand" hand-controls="hand: right; handModelStyle: lowPoly; color: #909c9f" laser-controls="button: trackpad" raycaster="showLine: true; far: 10; interval: 0; objects: .clickable, a-link;" line="color: #7cfc00; opacity: 0.5" visible="true"></a-entity>
    </a-entity>
	
	<!--Light.-->
		<a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
	</a-scene>
	</body>
</html>'''
        # ECRIT LES LIGNES D'ASSETS ET DE PLACEMENT
        for ob in f:
            result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
            
            result2 += "%s" % ("\n\t\t<a-entity position=\"0 0 0\" scale=\"1 1 1\" collada-model=\"src: #" + str(ob)[:-4] + "; colorCorrection: true\"></a-entity>")
 
        for tele in g:
            result3 += "%s" % ("\n\t\t<a-asset-item id=\"" + str(tele)[:-4] + "-obj" + "\"" + " src=\"../asset/teleport/" + str(tele) + "\"></a-asset-item> ")
            
            result4 += "%s" % ("\n\t\t<a-entity obj-model=\"obj: " + "#" + str(tele)[:-4]+ "-obj;\" material=\"opacity: 0\" id=\"" + str(tele)[:-4] + "\" position=\"\" rotation=\"\" scale=\"1\"></a-entity>")
            
            result5 += "%s" % ("#" + str(tele)[:-4] + ", """) 
            
            
      
          
            
    
        filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\webxr\\', (projet) +  ".html")
        file = open(filename, "w", encoding="utf-8")
        file.write(a + projet + b + result + c + result3 + ctele + result6 + cplace + result2 + d + result4 + dtele  + result5 +dteleplace)
        file.close()
        return {'FINISHED'}
        


# WRITTEN THE CODE LINES FOR 6DOF HEADSETS FOR THE STREET THEATER
# ECRIT LES LIGNES DE CODE POUR LES CASQUES 6DOF RUE
class SIXDOFRUE_OT_SixdofRue(bpy.types.Operator):
    bl_idname = "object.sixdofrue"
    bl_label = "Save html for heaset (webXR) Collada"
    bl_description = "Write file html for headset 6DOF for road"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        sound = bpy.context.scene.my_tool.my_string1
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        result4 = ""
        result5 = ""
        result6 = ""
        
        # filtre les fichiers DAE pour les casques 6DOF dans le dossier "models" du dossier du projet
        extentions = ["dae"]
        e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
        newList = []
        for word in e:
            if not word.startswith('._'):
                newList.append(word)
                f = newList
        
        # filtre les fichiers obj pour les casques 6DOF dans le dossier "teleport" du dossier du projet           
        newExtentions = ["obj"]
        g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
        teleportList = []
        
        

                          
		# Début page Html
        a = '''<html>
	<head>
	<title>'''
        b = '''</title>
    <script src="../../components/script/aframe-v1.1.0.min.js"></script>
    <script src="../../components/script/collada-model.js"></script>
    <script src="../../components/script/aframe-extras.min.js"></script>
    <script src="../../components/script/aframe-teleport-controls.js"></script>
	<!--The MIT License (MIT) Copyright (c) 2017 Fernando Serrano; Copyright (c) 2016 Don McCurdy -->
	</head>
	<body>
	
	<a-scene antialias="true">
	<!--Déclaration-->
		<a-assets>
		<!-- teleportation salle -->
        <a-asset-item id="leurreRue-obj" src="../../components/theatre/teleport/leurreRue.obj"></a-asset-item>
        
		<!--le decor-->
		<!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
		# ecriture des assets
		# suite page html
        c = '''\n\n\t\t<!-- teleportation plateau -->
		<!--A REMPLACER CI-DESSOUS LISTE DES ASSETS DE TELEPORTATIONS GENERE PAR BLENDER-->'''
		
        # ecriture des teleportations
        ctele = '''<!--Link-->
		<img id="sortie" src="../../components/link/sortie.jpg">
		</a-assets>
	<!--Fin Déclaration-->
	
		<!--image de fond.-->
		<a-sky color="black"></a-sky>
	
	
	<!--placement-->
    <!--sound-->'''
		#ecriture du son	

        cplace = '''\n\n\t\t<!-- teleportation salle -->
        <a-entity obj-model="obj: #leurreRue-obj;" material="opacity: 0" id="leurreRue" position="" rotation="" scale="1"></a-entity>
		
		<!--le decor-->
		<!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
        # ecriture des placements
        
        d = '''\n\n\t\t<!-- teleportation plateau -->
		<!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS DES TELEPORTATIONS GENERE PAR BLENDER -->'''
		
        # ecriture des placements de teleportations
        dtele = '''\n\n\t<!--Fin placement-->
	
	<!--Links-->
		    <!--menu-- <a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/mixedRea/menu.html" title="menu" image="#menu" position="7.6 2.91 6.22" rotation="0.0 90.0 0.0" scale="0.2 0.2 0.2"></a-link>-->
	  
	<!-- Player -->
	<!-- camera -->
	<a-entity id="cameraRig">
		<a-entity id="head" camera wasd-controls look-controls></a-entity>
		
		<!-- gachette -->
		<!--A REMPLACER CI-DESSOUS collisioEntity par les cibles de téléportation-->
		<a-entity
		teleport-controls="button: trigger; 
		cameraRig: #cameraRig; 
		teleportOrigin: #head;
		collisionEntities: '''
        
        #ecriture des teleportation dans le player
        dteleplace = '''#leurreRue;
		curveLineWidth: 0.01;
		curveHitColor: #eaf1ea;
		hitCylinderColor: #eaf1ea; 
		hitCylinderHeight:0.1; 
		hitCylinderRadius: 0.1" 
		hand-controls="hand: right; 
        handModelStyle: lowPoly; 
        color: #909c9f" 
        position="" rotation="" scale="" visible="" 
        vive-controls="" 
        oculus-touch-controls="" 
        windows-motion-controls="" 
        oculus-go-controls="hand: right"
        gearvr-controls="hand: right"></a-entity>
        <a-entity id="rightHand" hand-controls="hand: right; handModelStyle: lowPoly; color: #909c9f" laser-controls="button: trackpad" raycaster="showLine: true; far: 10; interval: 0; objects: .clickable, a-link;" line="color: #7cfc00; opacity: 0.5" visible="true"></a-entity>
    </a-entity>
	
	<!--Light.-->
		<a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
	</a-scene>
	</body>
</html>'''
        # ECRIT LES LIGNES D'ASSETS ET DE PLACEMENT
        for ob in f:
            result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
            
            result2 += "%s" % ("\n\t\t<a-entity position=\"0 0 0\" scale=\"1 1 1\" collada-model=\"src: #" + str(ob)[:-4] + "; colorCorrection: true\"></a-entity>")
         
 
        for tele in g:
            result3 += "%s" % ("\n\t\t<a-asset-item id=\"" + str(tele)[:-4] + "-obj" + "\"" + " src=\"../asset/teleport/" + str(tele) + "\"></a-asset-item> ")
            
            result4 += "%s" % ("\n\t\t<a-entity obj-model=\"obj: " + "#" + str(tele)[:-4]+ "-obj;\" material=\"opacity: 0\" id=\"" + str(tele)[:-4] + "\" position=\"\" rotation=\"\" scale=\"1\"></a-entity>")
            
            
            result5 += "%s" % ("#" + str(tele)[:-4] + ", """)
        
       
            
                
         
        filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\webxr\\', (projet) +  ".html")
        file = open(filename, "w", encoding="utf-8")
        file.write(a + projet + b + result + c + result3 + ctele + result6 + cplace + result2 + d + result4 + dtele  + result5 + dteleplace)
        file.close()
        return {'FINISHED'}
        



# WRITTEN THE CODE LINES FOR smartphone FOR THE ROOM THEATER  
# ECRIT LES LIGNES DE CODE POUR LES CARBOARD POUR LE THEATRE EN SALLE
class CARDBO_OT_smartphone(bpy.types.Operator):
    bl_idname = "object.smartphone"
    bl_label = "Save html for smartphone (webVR) Collada"
    bl_description = "Write file html for smartphone"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
		
        pathTeleport = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone"
    
        if os.listdir(pathTeleport) == []:
            def ShowMessageBox(message = "", title = "You don't have any Empty for teleport in carboard", icon = 'ERROR'):

                def draw(self, context):
                    self.layout.label(message)                                
                bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

          
            ShowMessageBox("You must create empty") 
            return {'FINISHED'}
        
        else :

            # filtre les fichiers DAE pour les casques smartphone dans le dossier "models" du dossier du projet
            extentions = ["dae"]
            e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
            newList = []
            
            for word in e:
                if not word.startswith('._'):
                    newList.append(word)
                    f = newList
                 
             # filtre les fichiers obj pour les casques 3DOF dans le dossier "teleport" du dossier du projet           
            newExtentions = ["obj"]
            g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
            teleportList = []
            
            #recupere les teleportations des smartphone
            teleportName = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone", "teleport.txt")
            with open (teleportName) as fp:
                lire =fp.read()
                
           
            
            # Début page Html
            a = '''<html>
    	<head>
    	<title>'''
            b = ''' pour smartphone</title>
    		<script src="../../components/script/smart/aframe.min.js"></script>
            <script src="../../components/script/smart/aframe-extras.min.js"></script>
    	</head>
    	<body>
    		<script>
    		console.log(AFRAME);
    		AFRAME.registerComponent('warp-to', {
    		schema: {},
    		init: function () {
    			var self = this;
    			var vector = new THREE.Vector3();
    			this.el.addEventListener('click', function() {
    				var camera3D = self.el.sceneEl.querySelector("#camera");
    				var animation = document.createElement('a-animation');	
    				animation.setAttribute('attribute', 'position');
    				const {x, y, z} = self.el.getAttribute('position');
                    animation.setAttribute('dur', 5000);
    				animation.setAttribute('to', `${x} ${y} ${z}`);
    				animation.setAttribute('easing', 'ease-in');
    				animation.addEventListener('animationend', function() {
    					camera.removeChild(animation);
    				});
    				camera.appendChild(animation);
    				console.log('clicked');
    			});
    		},
    		update: function () {},
    		tick: function () {},
    		remove: function () {},
    		pause: function () {},
    		play: function () {}
    		});
    		</script>
    		
    	<a-scene antialias="true">
    	<!--Déclaration-->
    		<a-assets>
    		<!--le theatre-->
    		<a-mixin id="button" cursor-listener></a-mixin>
    		<a-asset-item id="salle" src="../../components/theatre/models/salle.dae"></a-asset-item>
    		<a-asset-item id="siege" src="../../components/theatre/models/siege.dae"></a-asset-item>
    		<a-asset-item id="accotoir" src="../../components/theatre/models/accotoir.dae"></a-asset-item>
    		<a-asset-item id="pendard" src="../../components/theatre/models/pendard.dae"></a-asset-item>
            <a-asset-item id="bloc" src="../../components/theatre/models/bloc.dae"></a-asset-item>
    		
    		<!--le decor-->
    		<!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
    		# ecriture des assets
    		# suite page html
            c = '''\n\n\t\t<!--la téléportation-->
    		<asset><a-octahedron id="deplace"></a-octahedron>
    		</a-assets>
    	<!--Fin Déclaration-->
    		
    		<!--image de fond.-->
    		<a-sky color="black"></a-sky>
    		

    		
    	<!--Placement-->
    		<!--le theatre-->
    		<a-collada-model src="#salle" position="0 0 0"></a-collada-model>
    		<a-collada-model src="#siege" position="0 0 0"></a-collada-model>
    		<a-collada-model src="#accotoir" position="0 0 0"></a-collada-model>
    		<a-collada-model src="#pendard" position="0 0 0"></a-collada-model>
            
		    <!--Link-->
		    <a-collada-model src="#bloc" navigate-on-click="url: ../../menu/smartphone/menu.html" position="0 0 0"></a-collada-model>
    		
    		<!--le decor-->
    		<!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
            d = '''\n\n\t\t<!--téléportation à 1m65-->
    		<!--SALLE-->
    		<a-entity>
    		<!--x_salleFaceCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="5.55 0.78 1.65" warp-to></a-octahedron>
    		<!--x_salleFaceJardin--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-5.55 0.78 1.65" warp-to></a-octahedron>
    		<!--x_sceneFaceCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="3.76 1.31 -2.45" warp-to></a-octahedron>
    		<!--x_salleFaceMilieu--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-0.01 0.78 1.65" warp-to></a-octahedron>
    		<!--x_salleLointainCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="5.55 3.21 9.66" warp-to></a-octahedron>
    		<!--x_salleLointainJardin--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-5.55 3.21 9.66" warp-to></a-octahedron>
    		<!--x_salleLointainMilieu--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-0.01 3.21 9.66" warp-to></a-octahedron>
    		<!--x_salleMilieuCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="5.55 2.0 5.71" warp-to></a-octahedron>
    		<!--x_salleMilieuJardin--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-5.55 2.0 5.71" warp-to></a-octahedron>
    		<!--x_salleMilieuMilieu--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-0.01 2.0 5.71" warp-to></a-octahedron>
    		
    		<!--SCENE-->
    		<!--A REMPLACER CI-DESSOUS LISTE DES TELEPORTATIONS GENERE PAR BLENDER -->
    '''
            
            #placement des teleportations de la scene
            
            dteleplace = '''\n\t\t</a-entity>
    	<!--Fin placement-->
        <!--Link-->
        
    		
    	<!-- Player -->
    		<a-entity camera look-controls wasd-controls id="camera" position="0 1.6 3.5">
    		<a-entity cursor="fuse: true; far: 20" position="0 0 -3" geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03" material="color: white; shader: flat">
    		<a-animation begin="cursor-hovering" easing="ease-in" attribute="scale" fill="forwards" from="1 1 1" to="1.2 1.2 1.2"></a-animation>
    			</a-entity>
    		</a-entity>
    		
    	<!--Light.--> 
    		<a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
    	</a-scene>
        
        <script>
		  var scene = document.querySelector('a-scene');
		  if (scene.hasLoaded) {
			 run();
		  } else {
			 scene.addEventListener('loaded', run);
		  }
		  function run() {
			 scene.enterVR();
		  }
	     </script>
    	</body>
    </html>'''
            
            for ob in f:
                result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
                
                result2 += "%s" % ("\n\t\t<a-collada-model src=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-collada-model>")
            
      
            
            filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\smartphone\\', (projet) +  ".html")
            file = open(filename, "w", encoding="utf-8")
            file.write(a + projet + b + result + c + result2 + d + str(lire) + dteleplace)
            file.close()
            return {'FINISHED'}




# WRITTEN THE CODE LINES FOR smartphone FOR THE STREET THEATER  
# ECRIT LES LIGNES DE CODE POUR LES CARBOARD POUR LE THEATRE DE RUE
class CARBORUEsmartphoneRue(bpy.types.Operator):
    bl_idname = "object.smartphonerue"
    bl_label = "Save html for smartphone (webVR) Collada"
    bl_description = "Write file html for smartphone"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
		
        pathTeleport = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone"
    
        if os.listdir(pathTeleport) == []:
            def ShowMessageBox(message = "", title = "You don't have any Empty for teleport in smartphone", icon = 'ERROR'):

                def draw(self, context):
                    self.layout.label(message)                                
                bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

          
            ShowMessageBox("You must create empty") 
            return {'FINISHED'}
        
        else :

            # filtre les fichiers DAE pour les casques smartphone dans le dossier "models" du dossier du projet
            extentions = ["dae"]
            e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
            newList = []
            
            for word in e:
                if not word.startswith('._'):
                    newList.append(word)
                    f = newList
                 
             # filtre les fichiers obj pour les casques 3DOF dans le dossier "teleport" du dossier du projet           
            newExtentions = ["obj"]
            g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
            teleportList = []
            
            #recupere les teleportations des smartphone
            teleportName = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone", "teleport.txt")
            with open (teleportName) as fp:
                lire =fp.read()
            
            fp.close()
            
            # Début page Html
            a = '''<html>
    	<head>
    	<title>'''
            b = ''' pour smartphone</title>
    		<script src="../../components/script/smart/aframe.min.js"></script>
            <script src="../../components/script/smart/aframe-extras.min.js"></script>
    	</head>
    	<body>
    		<script>
    		console.log(AFRAME);
    		AFRAME.registerComponent('warp-to', {
    		schema: {},
    		init: function () {
    			var self = this;
    			var vector = new THREE.Vector3();
    			this.el.addEventListener('click', function() {
    				var camera3D = self.el.sceneEl.querySelector("#camera");
    				var animation = document.createElement('a-animation');	
    				animation.setAttribute('attribute', 'position');
    				const {x, y, z} = self.el.getAttribute('position');
    				animation.setAttribute('dur', 5000);
                    animation.setAttribute('to', `${x} ${y} ${z}`);
    				animation.setAttribute('easing', 'ease-in');
    				animation.addEventListener('animationend', function() {
    					camera.removeChild(animation);
    				});
    				camera.appendChild(animation);
    				console.log('clicked');
    			});
    		},
    		update: function () {},
    		tick: function () {},
    		remove: function () {},
    		pause: function () {},
    		play: function () {}
    		});
    		</script>
    
    		
    	<a-scene antialias="true">
    	<!--Déclaration-->
    		<a-assets>
      <!--le theatre-->
    		    
    		
    		<!--le decor-->
    		<!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
    		# ecriture des assets
    		# suite page html
            c = '''\n\n\t\t<!--la téléportation-->
    		<asset><a-octahedron id="deplace"></a-octahedron>
    		</a-assets>
    	<!--Fin Déclaration-->
    		
    		<!--image de fond.-->
    		<a-sky color="black"></a-sky>
    		

    		
    	<!--Placement-->
    		<!--le theatre-->
    		
    		
    		<!--le decor-->
    		<!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
            d = '''\n\n\t\t<!--téléportation à 1m65-->
    		<!--SALLE-->
    		<a-entity>
    		
    		<!--SCENE-->
    		<!--A REMPLACER CI-DESSOUS LISTE DES TELEPORTATIONS GENERE PAR BLENDER -->
    '''
            
            #placement des teleportations de la scene
            
            dteleplace = '''\n\t\t</a-entity>
    	<!--Fin placement-->
    		
    	<!-- Player -->
    		<a-entity camera look-controls wasd-controls id="camera" position="0 1.6 3.5">
    		<a-entity cursor="fuse: true; far: 20" position="0 0 -3" geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03" material="color: white; shader: flat">
    		<a-animation begin="cursor-hovering" easing="ease-in" attribute="scale" fill="forwards" from="1 1 1" to="1.2 1.2 1.2"></a-animation>
    			</a-entity>
    		</a-entity>
    		
    	<!--Light.--> 
    		<a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
    	</a-scene>
        
        <script>
		  var scene = document.querySelector('a-scene');
		  if (scene.hasLoaded) {
			 run();
		  } else {
			 scene.addEventListener('loaded', run);
		  }
		  function run() {
			 scene.enterVR();
		  }
	     </script>
    	</body>
    </html>'''
            
            for ob in f:
                result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
                
                result2 += "%s" % ("\n\t\t<a-collada-model src=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-collada-model>")
            
      
            
            filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\smartphone\\', (projet) +  ".html")
            file = open(filename, "w", encoding="utf-8")
            file.write(a + projet + b + result + c + result2 + d + str(lire) + dteleplace)
            file.close()
            return {'FINISHED'}



# WRITTEN THE CODE LINES FOR COMPUTER FOR THE ROOM THEATER  
# ECRIT LES LIGNES DE CODE POUR LES ORDINATEURS POUR LE THEATRE EN SALLE
class ORDI_OT_Ordi(bpy.types.Operator):
    bl_idname = "object.computer"
    bl_label = "Save html for Computeur (webVR) Collada"
    bl_description = "Write file html for computer"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        
        pathTeleport = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone"
    
        if os.listdir(pathTeleport) == []:
            def ShowMessageBox(message = "", title = "You don't have any Empty for teleport in carboard", icon = 'ERROR'):

                def draw(self, context):
                    self.layout.label(message)                                
                bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

          
            ShowMessageBox("You must create empty") 
            return {'FINISHED'}
        
        else :

            # filtre les fichiers DAE pour les casques smartphone dans le dossier "models" du dossier du projet
            extentions = ["dae"]
            e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
            newList = []
            
            for word in e:
                if not word.startswith('._'):
                    newList.append(word)
                    f = newList
                    
             # filtre les fichiers DAE pour les liens des ordinateurs
            extentionsLien = ["dae"]
            m = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\modelsForlinkOrdi\\') if fn.split(".")[-1] in extentionsLien]
            newListLien = []
            
            for word in m:
                if not word.startswith('._'):
                    newListLien.append(word)
                    p = newListLien
                 
             # filtre les fichiers obj pour les casques 3DOF dans le dossier "teleport" du dossier du projet           
            newExtentions = ["obj"]
            g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
            teleportList = []
            
            #recupere les teleportations des smartphone
            teleportName = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone", "teleport.txt")
            with open (teleportName) as fp:
                lire =fp.read()
                
            
            # Début page Html
            a = '''<html>
        <head>
        <title>'''
            b = ''' pour ordinateur</title>
            <script src="../../components/script/aframe-extras.js"></script>
        </head>
        <body>
            <script>
            console.log(AFRAME);
            AFRAME.registerComponent('warp-to', {
            schema: {},
            init: function () {
                var self = this;
                var vector = new THREE.Vector3();
                this.el.addEventListener('click', function() {
                    var camera3D = self.el.sceneEl.querySelector("#camera");
                    var animation = document.createElement('a-animation');	
                    animation.setAttribute('attribute', 'position');
                    const {x, y, z} = self.el.getAttribute('position');
                    animation.setAttribute('dur', 5000);
                    animation.setAttribute('to', `${x} ${y} ${z}`);
                    animation.setAttribute('easing', 'ease-in');
                    animation.addEventListener('animationend', function() {
                        camera.removeChild(animation);
                    });
                    camera.appendChild(animation);
                    console.log('clicked');
                });
            },
            update: function () {},
            tick: function () {},
            remove: function () {},
            pause: function () {},
            play: function () {}
            });
            </script>
            <script>
                AFRAME.registerComponent('navigate-on-click', {
                    schema: {
                        url: { default: '' }
                    },
        
                    init: function () {
                        var data = this.data;
                        var el = this.el;
        
                        el.addEventListener('click', function () {
                            window.location.href = data.url;
                        });
                    }
                });        
            </script>
            
        <a-scene antialias="true">
        <!--Déclaration-->
            <a-assets>
            <!--le theatre-->
            <a-mixin id="button" cursor-listener></a-mixin>
            <a-asset-item id="salle" src="../../components/theatre/models/salle.dae"></a-asset-item>
            <a-asset-item id="siege" src="../../components/theatre/models/siege.dae"></a-asset-item>
            <a-asset-item id="accotoir" src="../../components/theatre/models/accotoir.dae"></a-asset-item>
            <a-asset-item id="pendard" src="../../components/theatre/models/pendard.dae"></a-asset-item>
            <a-asset-item id="bloc" src="../../components/theatre/models/bloc.dae"></a-asset-item>
            
            <!--le decor-->
            <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
            # ecriture des assets
            # suite page html
            c = '''\n\n\t\t<!--la téléportation-->
            <asset><a-octahedron id="deplace"></a-octahedron>
            </a-assets>
        <!--Fin Déclaration-->
            
            <!--image de fond.-->
            <a-sky color="black"></a-sky>
            

            
        <!--Placement-->
            <!--le theatre-->
            <a-collada-model src="#salle" position="0 0 0"></a-collada-model>
            <a-collada-model src="#siege" position="0 0 0"></a-collada-model>
            <a-collada-model src="#accotoir" position="0 0 0"></a-collada-model>
            <a-collada-model src="#pendard" position="0 0 0"></a-collada-model>
            
        <!--Link--
            <a-collada-model src="#bloc" navigate-on-click="url: ../../menu/ordinateur/menu.html" position="0 0 0"></a-collada-model>-->
          
        <!--le decor-->
            <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
            
            d = '''\n\n\t\t<!--téléportation à 1m65-->
            <!--SALLE-->
            <a-entity>
            <!--x_salleFaceCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="5.55 0.78 1.65" warp-to></a-octahedron>
            <!--x_salleFaceJardin--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-5.55 0.78 1.65" warp-to></a-octahedron>
            <!--x_sceneFaceCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="3.76 1.31 -2.45" warp-to></a-octahedron>
            <!--x_salleFaceMilieu--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-0.01 0.78 1.65" warp-to></a-octahedron>
            <!--x_salleLointainCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="5.55 3.21 9.66" warp-to></a-octahedron>
            <!--x_salleLointainJardin--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-5.55 3.21 9.66" warp-to></a-octahedron>
            <!--x_salleLointainMilieu--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-0.01 3.21 9.66" warp-to></a-octahedron>
            <!--x_salleMilieuCour--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="5.55 2.0 5.71" warp-to></a-octahedron>
            <!--x_salleMilieuJardin--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-5.55 2.0 5.71" warp-to></a-octahedron>
            <!--x_salleMilieuMilieu--><a-octahedron color="red" scale="0.1 0.3 0.1" radius="1" opacity="0.2" position="-0.01 2.0 5.71" warp-to></a-octahedron>
            
            <!--SCENE-->
            <!--A REMPLACER CI-DESSOUS LISTE DES TELEPORTATIONS GENERE PAR BLENDER -->
    '''
            
            #placement des teleportations de la scene
            
            dteleplace = '''\n\t\t</a-entity>
        <!--Fin placement-->    
        
            
        <!-- Player -->
            <a-entity camera look-controls wasd-controls id="camera" position="0 1.6 3.5">
            <a-entity cursor="fuse: true; far: 20" position="0 0 -3" geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03" material="color: white; shader: flat">
            <a-animation begin="cursor-hovering" easing="ease-in" attribute="scale" fill="forwards" from="1 1 1" to="1.2 1.2 1.2"></a-animation>
                </a-entity>
            </a-entity>
            
        <!--Light.--> 
            <a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
        </a-scene>
        
        <script>
          var scene = document.querySelector('a-scene');
          if (scene.hasLoaded) {
             run();
          } else {
             scene.addEventListener('loaded', run);
          }
          function run() {
             scene.enterVR();
          }
         </script>
        </body>
    </html>'''
            
            for ob in f:
                result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
                
                result2 += "%s" % ("\n\t\t<a-collada-model src=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-collada-model>")
           
      
            
            filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\ordinateur\\', (projet) +  ".html")
            file = open(filename, "w", encoding="utf-8")
            file.write(a + projet + b + result + result3 + c  + result2 + d + str(lire) + dteleplace)
            file.close()
            return {'FINISHED'}




# WRITTEN THE CODE LINES FOR COMPUTER FOR THE STREET THEATER  
# ECRIT LES LIGNES DE CODE POUR LES ORDINATEURS POUR LE THEATRE DE RUE
class ORDI_OT_Ordirue(bpy.types.Operator):
    bl_idname = "object.computerrue"
    bl_label = "Save html for Computeur (webVR) Collada"
    bl_description = "Write file html for ordinateur rue"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        
        pathTeleport = "" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone"
    
        if os.listdir(pathTeleport) == []:
            def ShowMessageBox(message = "", title = "You don't have any Empty for teleport in carboard", icon = 'ERROR'):

                def draw(self, context):
                    self.layout.label(message)                                
                bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

          
            ShowMessageBox("You must create empty") 
            return {'FINISHED'}
        
        else :

            # filtre les fichiers DAE pour les casques smartphone dans le dossier "models" du dossier du projet
            extentions = ["dae"]
            e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
            newList = []
            
            for word in e:
                if not word.startswith('._'):
                    newList.append(word)
                    f = newList
                    
                    
            # filtre les fichiers DAE pour les liens des ordinateurs
            extentionsLien = ["dae"]
            m = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\modelsForlinkOrdi\\') if fn.split(".")[-1] in extentionsLien]
            newListLien = []
            
            for word in m:
                if not word.startswith('._'):
                    newListLien.append(word)
                    p = newListLien        
                    
                    
                 
             # filtre les fichiers obj pour les casques 3DOF dans le dossier "teleport" du dossier du projet           
            newExtentions = ["obj"]
            g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
            teleportList = []
            
            #recupere les teleportations des smartphone
            teleportName = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\teleportsmartphone", "teleport.txt")
            with open (teleportName) as fp:
                lire =fp.read()
            
            fp.close()
            
            
           
            
            # Début page Html
            a = '''<html>
        <head>
        <title>'''
            b = ''' pour ordinateur</title>
            <script src="../../components/script/aframe-extras.js"></script>
        </head>
        <body>
            <script>
            console.log(AFRAME);
            AFRAME.registerComponent('warp-to', {
            schema: {},
            init: function () {
                var self = this;
                var vector = new THREE.Vector3();
                this.el.addEventListener('click', function() {
                    var camera3D = self.el.sceneEl.querySelector("#camera");
                    var animation = document.createElement('a-animation');	
                    animation.setAttribute('attribute', 'position');
                    const {x, y, z} = self.el.getAttribute('position');
                    animation.setAttribute('dur', 5000);
                    animation.setAttribute('to', `${x} ${y} ${z}`);
                    animation.setAttribute('easing', 'ease-in');
                    animation.addEventListener('animationend', function() {
                        camera.removeChild(animation);
                    });
                    camera.appendChild(animation);
                    console.log('clicked');
                });
            },
            update: function () {},
            tick: function () {},
            remove: function () {},
            pause: function () {},
            play: function () {}
            });
            </script>
    
            <script>
                AFRAME.registerComponent('navigate-on-click', {
                    schema: {
                        url: { default: '' }
                    },
        
                    init: function () {
                        var data = this.data;
                        var el = this.el;
        
                        el.addEventListener('click', function () {
                            window.location.href = data.url;
                        });
                    }
                });        
            </script>
            
        <a-scene antialias="true">
        <!--Déclaration-->
            <a-assets>
      <!--le theatre-->
                
            
            <!--le decor-->
            <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
            # ecriture des assets
            # suite page html
            c = '''\n\n\t\t<!--la téléportation-->
            <asset><a-octahedron id="deplace"></a-octahedron>
            </a-assets>
        <!--Fin Déclaration-->
            
            <!--image de fond.-->
            <a-sky color="black"></a-sky>
            

            
        <!--Placement-->
            <!--le theatre-->
         
         <!--Link<a-collada-model src="#bloc" navigate-on-click="url: ../../menu/ordinateur/menu.html" position="0 0 0"></a-collada-model>-->
              
            
        <!--le decor-->
            <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
            d = '''\n\n\t\t<!--téléportation à 1m65-->
            <!--SALLE-->
            <a-entity>
            
            <!--SCENE-->
            <!--A REMPLACER CI-DESSOUS LISTE DES TELEPORTATIONS GENERE PAR BLENDER -->
    '''
            
            #placement des teleportations de la scene
            
            dteleplace = '''\n\t\t</a-entity>
        <!--Fin placement-->
            
        <!-- Player -->
            <a-entity camera look-controls wasd-controls id="camera" position="0 1.6 3.5">
            <a-entity cursor="fuse: true; far: 20" position="0 0 -3" geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03" material="color: white; shader: flat">
            <a-animation begin="cursor-hovering" easing="ease-in" attribute="scale" fill="forwards" from="1 1 1" to="1.2 1.2 1.2"></a-animation>
                </a-entity>
            </a-entity>
            
        <!--Light.--> 
            <a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
        </a-scene>
        
        <script>
          var scene = document.querySelector('a-scene');
          if (scene.hasLoaded) {
             run();
          } else {
             scene.addEventListener('loaded', run);
          }
          function run() {
             scene.enterVR();
          }
         </script>
        </body>
    </html>'''
            
            for ob in f:
                result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
                
                result2 += "%s" % ("\n\t\t<a-collada-model src=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-collada-model>")
            
      
            
            filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\ordinateur\\', (projet) +  ".html")
            file = open(filename, "w", encoding="utf-8")
            file.write(a + projet + b + result + result3 + c  + result2 + d + str(lire) + dteleplace)
            file.close()
            return {'FINISHED'}


# WRITTEN THE CODE LINES FOR 6DOF HEADSETS FOR THE ROOM THEATER               
# ECRIT LES LIGNES DE CODE POUR LES CASQUES 6DOF POUR LE THEATRE EN SALLE
class SIXDOF_OT_Sixdofvr(bpy.types.Operator):
    bl_idname = "object.sixdofvr"
    bl_label = "Save html for headset (webVR) Collada"
    bl_description = "Write file html for headset 6DOF"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        sound = bpy.context.scene.my_tool.my_string1
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        result4 = ""
        result5 = ""
        result6 = ""
        
        #filters DAE files for 6DOF headsets in the "models" folder of the project folder
        # filtre les fichiers DAE pour les casques 6DOF dans le dossier "models" du dossier du projet
        extentions = ["dae"]
        e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
        newList = []
        for word in e:
            if not word.startswith('._'):
                newList.append(word)
                f = newList
        
        # filters the obj files for 6DOF headsets in the "teleport" folder of the project folder
        # filtre les fichiers obj pour les casques 6DOF dans le dossier "teleport" du dossier du projet           
        newExtentions = ["obj"]
        g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
        teleportList = []
        

        # Start Html page                  
        # Début page Html
        a = '''<html>
    <head>
    <title>'''
        b = '''</title>
    <script src="../../components/script/casque/aframe.min.js"></script>
    <script src="../../components/script/casque/aframe-extras.min.js"></script>
    <script src="../../components/script/casque/aframe-teleport-controls.min.js"></script>
    <script src="../../components/script/casque/link-controls.js"></script>
    <!--The MIT License (MIT) Copyright (c) 2017 Fernando Serrano; Copyright (c) 2016 Don McCurdy -->
    </head>
    <body>
    
    <a-scene antialias="true">
    <!--Déclaration-->
        <a-assets>
        <!--la salle-->
        <a-asset-item id="salle" src="../../components/theatre/models/salle.dae"></a-asset-item>
        <a-asset-item id="siege" src="../../components/theatre/models/siege.dae"></a-asset-item>
        <a-asset-item id="accotoir" src="../../components/theatre/models/accotoir.dae"></a-asset-item>
        <a-asset-item id="pendard" src="../../components/theatre/models/pendard.dae"></a-asset-item>
        <a-asset-item id="box" src="../../components/theatre/models/box.dae"></a-asset-item>
        <a-asset-item id="bloc" src="../../components/theatre/models/bloc.dae"></a-asset-item>
        <!--cloison1-->
        
        <!-- teleportation salle -->
        <a-asset-item id="salle_niv1_tele-obj" src="../../components/theatre/teleport/salle_niv1_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv2_tele-obj" src="../../components/theatre/teleport/salle_niv2_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv3_tele-obj" src="../../components/theatre/teleport/salle_niv3_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv4_tele-obj" src="../../components/theatre/teleport/salle_niv4_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv5_tele-obj" src="../../components/theatre/teleport/salle_niv5_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv6_tele-obj" src="../../components/theatre/teleport/salle_niv6_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv7_tele-obj" src="../../components/theatre/teleport/salle_niv7_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv8_tele-obj" src="../../components/theatre/teleport/salle_niv8_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv9_tele-obj" src="../../components/theatre/teleport/salle_niv9_tele.obj"></a-asset-item>
        <a-asset-item id="leurreRue-obj" src="../../components/theatre/teleport/leurreRue.obj"></a-asset-item>
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
        
        # ecriture des assets
        # suite page html
        c = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS DE TELEPORTATIONS GENERE PAR BLENDER-->'''
        
        # ecriture des teleportations
        ctele = '''<!--Link-->
        <img id="sortie" src="../../components/link/sortie.jpg">
        
        <!--One image the sky sky-->
        <!--<img  id="monImage" src="../asset/link/monImage.jpg"></img>-->
        
        <!--One video on the sky-->
        <!--<video id="video" style="display:none" 
                   autoplay loop crossorigin="anonymous" playsinline webkit-playsinline>
              <!-- MP4 video source. -->
              <source type="video/mp4"
                   src="../asset/link/maVideo.mp4" />
            </video>-->
        
        <!--One sound-->
        <!--<audio  id="son" src="../asset/link/monSon.mp3"></audio>-->
        
        </a-assets>
    <!--Fin Déclaration-->
    <!--placement--> 
        
        <!--image de fond.-->
        <a-sky color="black"></a-sky>
        
        <!--image in the sky-->
        <!--<a-sky  src="#sky"></a-sky>-->
        
        <!--video on the sky-->
        <!--<a-videosphere rotation="0 180 0" src="#video" 
                     play-on-window-click
                     play-on-vrdisplayactivate-or-enter-vr>
      </a-videosphere>-->
        
        <!--sound-->
        <!--<a-sound src="#son" autoplay="True"></a-sound>-->
    
    
        <!--La salle-->
        <a-collada-model src="#salle" position="0 0 0"></a-collada-model>
        <a-collada-model src="#siege" position="0 0 0"></a-collada-model>
        <a-collada-model src="#accotoir" position="0 0 0"></a-collada-model>
        <a-collada-model src="#pendard" position="0 0 0"></a-collada-model>
        <a-collada-model src="#box" position="0 0 0"></a-collada-model>
        <a-collada-model src="#bloc" position="0 0 0"></a-collada-model>
        <!--Cloison-->
        
        <!-- teleportation salle -->
        <a-entity obj-model="obj: #salle_niv1_tele-obj;" material="opacity: 0" id="salle_niv1_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv2_tele-obj;" material="opacity: 0" id="salle_niv2_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv3_tele-obj;" material="opacity: 0" id="salle_niv3_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv4_tele-obj;" material="opacity: 0" id="salle_niv4_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv5_tele-obj;" material="opacity: 0" id="salle_niv5_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv6_tele-obj;" material="opacity: 0" id="salle_niv6_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv7_tele-obj;" material="opacity: 0" id="salle_niv7_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv8_tele-obj;" material="opacity: 0" id="salle_niv8_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv9_tele-obj;" material="opacity: 0" id="salle_niv9_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #leurreRue-obj;" material="opacity: 0" id="leurreRue" position="" rotation="" scale="1"></a-entity>
    
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
        
        # placement writing
        # ecriture des placements
        
        d = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS DES TELEPORTATIONS GENERE PAR BLENDER -->'''
        
        # writing teleport placements
        # ecriture des placements de teleportations
        dtele = '''\n\n\t<!--Fin placement-->
    
    <!--One Links for outside-->
    <!--<a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/mixedRea/menu.html" title="menu" image="#menu" position="7.6 2.91 6.22" rotation="0.0 90.0 0.0" scale="0.2 0.2 0.2"></a-link>-->

    
    
    <!-- Player -->
    <!-- camera -->
    <a-entity id="cameraRig">
        <a-entity id="head" camera wasd-controls look-controls></a-entity>
        
        <!-- gachette -->
        <!--A REMPLACER CI-DESSOUS collisioEntity par les cibles de téléportation-->
        <a-entity
        teleport-controls="button: trigger; 
        cameraRig: #cameraRig; 
        teleportOrigin: #head;
        collisionEntities: '''
        
        #writing teleportation in the player
        #ecriture des teleportation dans le player
        dteleplace = '''#leurreRue, #salle_niv1_tele, #salle_niv2_tele, #salle_niv3_tele, #salle_niv4_tele, #salle_niv5_tele, #salle_niv6_tele, #salle_niv7_tele, #salle_niv8_tele, #salle_niv9_tele;
        curveLineWidth: 0.01;
        curveHitColor: #eaf1ea;
        hitCylinderColor: #eaf1ea; 
        hitCylinderHeight:0.1; 
        hitCylinderRadius: 0.1" 
        hand-controls="right" 
        position="" rotation="" scale="" visible="" 
        vive-controls="" 
        oculus-touch-controls="" 
        windows-motion-controls="" 
        oculus-go-controls="hand: right"
        gearvr-controls="hand: right"
        link-controls="button: trigger; hand: right"  position="" rotation="" scale="" visible="" vive-controls="" oculus-touch-controls="" windows-motion-controls="" gearvr-controls="">
        </a-entity>
    </a-entity>
    
    <!--Light.-->
        <a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
    </a-scene>
    </body>
</html>'''
        # ECRIT LES LIGNES D'ASSETS ET DE PLACEMENT
        for ob in f:
            result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
            
            result2 += "%s" % ("\n\t\t<a-collada-model src=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-collada-model>")
         
 
        for tele in g:
            result3 += "%s" % ("\n\t\t<a-asset-item id=\"" + str(tele)[:-4] + "-obj" + "\"" + " src=\"../asset/teleport/" + str(tele) + "\"></a-asset-item> ")
            
            result4 += "%s" % ("\n\t\t<a-entity obj-model=\"obj: " + "#" + str(tele)[:-4]+ "-obj;\" material=\"opacity: 0\" id=\"" + str(tele)[:-4] + "\" position=\"\" rotation=\"\" scale=\"1\"></a-entity>")
            
            result5 += "%s" % ("#" + str(tele)[:-4] + ", """) 
            
          
            
    
        filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\casque\\', (projet) +  ".html")
        file = open(filename, "w", encoding="utf-8")
        file.write(a + projet + b + result + c + result3 + ctele + result2 + d + result4 + dtele + result5 +dteleplace)
        file.close()
        return {'FINISHED'}
        


# WRITTEN THE CODE LINES FOR 6DOF HEADSETS FOR THE STREET THEATER
# ECRIT LES LIGNES DE CODE POUR LES CASQUES 6DOF RUE
class SIXDOFRUE_OT_SixdofRuevr(bpy.types.Operator):
    bl_idname = "object.sixdofruevr"
    bl_label = "Save html for headset (webVR) Collada"
    bl_description = "Write file html for headset 6DOF for road"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        sound = bpy.context.scene.my_tool.my_string1
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        result4 = ""
        result5 = ""
        result6 = ""
        
        # filtre les fichiers DAE pour les casques 6DOF dans le dossier "models" du dossier du projet
        extentions = ["dae"]
        e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\models\\') if fn.split(".")[-1] in extentions]
        newList = []
        for word in e:
            if not word.startswith('._'):
                newList.append(word)
                f = newList
        
        # filtre les fichiers obj pour les casques 6DOF dans le dossier "teleport" du dossier du projet           
        newExtentions = ["obj"]
        g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
        teleportList = []
        

                          
        # Début page Html
        a = '''<html>
    <head>
    <title>'''
        b = '''</title>
    <script src="../../components/script/casque/aframe.min.js"></script>
    <script src="../../components/script/casque/aframe-extras.min.js"></script>
    <script src="../../components/script/casque/aframe-teleport-controls.min.js"></script>
    <script src="../../components/script/casque/link-controls.js"></script>
    <!--The MIT License (MIT) Copyright (c) 2017 Fernando Serrano; Copyright (c) 2016 Don McCurdy -->
    </head>
    <body>
    
    <a-scene antialias="true">
    <!--Déclaration-->
        <a-assets>
        <!-- teleportation salle -->
        <a-asset-item id="leurreRue-obj" src="../../components/theatre/teleport/leurreRue.obj"></a-asset-item>
        
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
        # ecriture des assets
        # suite page html
        c = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS DE TELEPORTATIONS GENERE PAR BLENDER-->'''
        
        # ecriture des teleportations
        ctele = '''<!--Link-->
        <img id="sortie" src="../../components/link/sortie.jpg">
        
        <!--One image the sky sky-->
        <!--<img  id="monImage" src="../asset/link/monImage.jpg"></img>-->
        
        <!--One video on the sky-->
        <!--<video id="video" style="display:none" 
                   autoplay loop crossorigin="anonymous" playsinline webkit-playsinline>
              <!-- MP4 video source. -->
              <source type="video/mp4"
                   src="../asset/link/maVideo.mp4" />
            </video>-->
        
        <!--One sound-->
        <!--<audio  id="son" src="../asset/link/monSon.mp3"></audio>-->
        
        </a-assets>
    
    <!--Fin Déclaration-->
    
    <!--placement--> 
        
        <!--image de fond.-->
        <a-sky color="black"></a-sky>
        
        <!--image in the sky-->
        <!--<a-sky  src="#sky"></a-sky>-->
        
        <!--video on the sky-->
        <!--<a-videosphere rotation="0 180 0" src="#video" 
                     play-on-window-click
                     play-on-vrdisplayactivate-or-enter-vr>
      </a-videosphere>-->
        
        <!--sound-->
        <!--<a-sound src="#son" autoplay="True"></a-sound>-->
    
    
   
   <!-- teleportation salle -->
        <a-entity obj-model="obj: #leurreRue-obj;" material="opacity: 0" id="leurreRue" position="" rotation="" scale="1"></a-entity>
        
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
        # ecriture des placements
        
        d = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS DES TELEPORTATIONS GENERE PAR BLENDER -->'''
        
        # ecriture des placements de teleportations
        dtele = '''\n\n\t<!--Fin placement-->
    
    <!--One Links for outside-->
    <!--<a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/mixedRea/menu.html" title="menu" image="#menu" position="7.6 2.91 6.22" rotation="0.0 90.0 0.0" scale="0.2 0.2 0.2"></a-link>-->	
    <!-- Player -->
    <!-- camera -->
    <a-entity id="cameraRig">
        <a-entity id="head" camera wasd-controls look-controls></a-entity>
        
        <!-- gachette -->
        <!--A REMPLACER CI-DESSOUS collisioEntity par les cibles de téléportation-->
        <a-entity
        teleport-controls="button: trigger; 
        cameraRig: #cameraRig; 
        teleportOrigin: #head;
        collisionEntities: '''
        
        #ecriture des teleportation dans le player
        dteleplace = '''#leurreRue;
        curveLineWidth: 0.01;
        curveHitColor: #eaf1ea;
        hitCylinderColor: #eaf1ea; 
        hitCylinderHeight:0.1; 
        hitCylinderRadius: 0.1" 
        hand-controls="right" 
        position="" rotation="" scale="" visible="" 
        vive-controls="" 
        oculus-touch-controls="" 
        windows-motion-controls="" 
        oculus-go-controls="hand: right"
        gearvr-controls="hand: right"
        link-controls="button: trigger; hand: right"  position="" rotation="" scale="" visible="" vive-controls="" oculus-touch-controls="" windows-motion-controls="" gearvr-controls="">
        </a-entity>
    </a-entity>
    
    <!--Light.-->
        <a-light type="ambient" intensity="0.8" position="0 10 0"></a-light>
    </a-scene>
    </body>
</html>'''
        # ECRIT LES LIGNES D'ASSETS ET DE PLACEMENT
        for ob in f:
            result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/models/" + str(ob) + "\"></a-asset-item>") 
            
            result2 += "%s" % ("\n\t\t<a-collada-model src=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-collada-model>")
         
 
        for tele in g:
            result3 += "%s" % ("\n\t\t<a-asset-item id=\"" + str(tele)[:-4] + "-obj" + "\"" + " src=\"../asset/teleport/" + str(tele) + "\"></a-asset-item> ")
            
            result4 += "%s" % ("\n\t\t<a-entity obj-model=\"obj: " + "#" + str(tele)[:-4]+ "-obj;\" material=\"opacity: 0\" id=\"" + str(tele)[:-4] + "\" position=\"\" rotation=\"\" scale=\"1\"></a-entity>")
            
            
            result5 += "%s" % ("#" + str(tele)[:-4] + ", """)
        
        
    
            
                
         
        filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\casque\\', (projet) +  ".html")
        file = open(filename, "w", encoding="utf-8")
        file.write(a + projet + b + result + c + result3 + ctele + result2 + d + result4 + dtele + result5 + dteleplace)
        file.close()
        return {'FINISHED'}
        

# WRITTEN THE CODE WEBXR LINES FOR 6DOF HEADSETS FOR THE ROOM THEATER               
# ECRIT LES LIGNES DE CODE DE WEBXR POUR LES CASQUES 6DOF POUR LE THEATRE EN SALLE
class SIXDOFXR_OT_Sixdofxr(bpy.types.Operator):
    bl_idname = "object.sixdofxr"
    bl_label = "Save html for headset (webXR) GLTF"
    bl_description = "Write file html webXR for headset 6DOF"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        sound = bpy.context.scene.my_tool.my_string1
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        result4 = ""
        result5 = ""
        result6 = ""
        
        #filters GLTF files for 6DOF headsets in the "models" folder of the project folder
        # filtre les fichiers DAE pour les casques 6DOF dans le dossier "models" du dossier du projet
        extentions = ["glb"]
        e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\modelsXr\\') if fn.split(".")[-1] in extentions]
        newList = []
        for word in e:
            if not word.startswith('._'):
                newList.append(word)
                f = newList
        
        # filters the obj files for 6DOF headsets in the "teleport" folder of the project folder
        # filtre les fichiers obj pour les casques 6DOF dans le dossier "teleport" du dossier du projet           
        newExtentions = ["obj"]
        g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
        teleportList = []
        
        
         #recupere les liens vers d'autres expériences
        lienName = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\link", "link.txt")
        with open (lienName) as fp:
            lireLien =fp.read()
            
        fp.close()

        # Start Html page                  
        # Début page Html
        a = '''<html>
    <head>
    <meta charset="utf-8">
    <title>'''
        b = '''</title>
    <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
    <script src="../../components/webxr/script/aframe-extras.min.js"></script>
    <script src="../../components/webxr/script/aframe-teleport-controls.js"></script>
     
    <!--The MIT License (MIT) Copyright (c) 2017 Fernando Serrano; Copyright (c) 2016 Don McCurdy -->
    </head>
    <body>
    
    <a-scene antialias="true">
    <!--Déclaration-->
        <a-assets>
        <!--la salle-->
        <a-asset-item id="salle" src="../../components/webxr/theatre/models/salle.gltf"></a-asset-item>
        <a-asset-item id="accotoir" src="../../components/webxr/theatre/models/accotoir.gltf"></a-asset-item>
        <a-asset-item id="siege" src="../../components/webxr/theatre/models/siege.gltf"></a-asset-item> 
        <!--cloison1-->
        
        <!-- teleportation salle -->
        <a-asset-item id="salle_niv1_tele-obj" src="../../components/theatre/teleport/salle_niv1_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv2_tele-obj" src="../../components/theatre/teleport/salle_niv2_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv3_tele-obj" src="../../components/theatre/teleport/salle_niv3_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv4_tele-obj" src="../../components/theatre/teleport/salle_niv4_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv5_tele-obj" src="../../components/theatre/teleport/salle_niv5_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv6_tele-obj" src="../../components/theatre/teleport/salle_niv6_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv7_tele-obj" src="../../components/theatre/teleport/salle_niv7_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv8_tele-obj" src="../../components/theatre/teleport/salle_niv8_tele.obj"></a-asset-item>
        <a-asset-item id="salle_niv9_tele-obj" src="../../components/theatre/teleport/salle_niv9_tele.obj"></a-asset-item>
        <a-asset-item id="leurreRue-obj" src="../../components/theatre/teleport/leurreRue.obj"></a-asset-item>
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
        
        # ecriture des assets
        # suite page html
        c = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS DE TELEPORTATIONS GENERE PAR BLENDER-->'''
        
        # ecriture des teleportations
        ctele = '''<!--Link-->
        <img id="sortie" src="../../components/webxr/link/sortie.jpg">
        </a-assets>
    <!--Fin Déclaration-->
    
        <!--image de fond.-->
        <a-sky color="black"></a-sky>
    
    
    <!--placement--> 
        <!--La salle-->
        <!--sound-->'''
        #ecriture du son	

        cplace = '''\n\n\t\t <a-entity gltf-model="#salle" position ="0 0 0" ></a-entity> 
        <a-entity gltf-model="#accotoir" position ="0 0 0" ></a-entity> 
        <a-entity gltf-model="#siege" position ="0 0 0" ></a-entity> 
        <!--Cloison-->
        
        <!-- teleportation salle -->
        <a-entity obj-model="obj: #salle_niv1_tele-obj;" material="opacity: 0" id="salle_niv1_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv2_tele-obj;" material="opacity: 0" id="salle_niv2_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv3_tele-obj;" material="opacity: 0" id="salle_niv3_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv4_tele-obj;" material="opacity: 0" id="salle_niv4_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv5_tele-obj;" material="opacity: 0" id="salle_niv5_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv6_tele-obj;" material="opacity: 0" id="salle_niv6_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv7_tele-obj;" material="opacity: 0" id="salle_niv7_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv8_tele-obj;" material="opacity: 0" id="salle_niv8_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #salle_niv9_tele-obj;" material="opacity: 0" id="salle_niv9_tele" position="" rotation="" scale="1"></a-entity>
        <a-entity obj-model="obj: #leurreRue-obj;" material="opacity: 0" id="leurreRue" position="" rotation="" scale="1"></a-entity>
    
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
        
        # placement writing
        # ecriture des placements
        
        d = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS DES TELEPORTATIONS GENERE PAR BLENDER -->'''
        
        # writing teleport placements
        # ecriture des placements de teleportations
        dtele = '''\n\n\t<!--Fin placement-->
    
    <!--Links-->
        <a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/webxr/menu.html" title=" " image="#sortie" position="7.56 2.5 1.22" rotation="0 90 0" scale="0.1 0.1 0.1"></a-link>
        <a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/webxr/menu.html" title=" " image="#sortie" position="-7.58 2.5 1.39" rotation="0 -90 0" scale="0.1 0.1 0.1"></a-link>
      '''
            
        #placement des lien
            
        placeLien = '''  \n\t\t
    <!-- Player -->
    <!-- camera -->
    <a-entity id="cameraRig">
        <a-entity id="head" camera wasd-controls look-controls></a-entity>
        
        <!-- gachette -->
        <!--A REMPLACER CI-DESSOUS collisioEntity par les cibles de téléportation-->
        <a-entity
        id="lefthand"
        teleport-controls="button: trigger; 
        cameraRig: #cameraRig; 
        teleportOrigin: #head;
        collisionEntities: '''
        
        #writing teleportation in the player
        #ecriture des teleportation dans le player
        dteleplace = '''#leurreRue, #salle_niv1_tele, #salle_niv2_tele, #salle_niv3_tele, #salle_niv4_tele, #salle_niv5_tele, #salle_niv6_tele, #salle_niv7_tele, #salle_niv8_tele, #salle_niv9_tele;
        curveLineWidth: 0.01;
        curveHitColor: #eaf1ea;
        hitCylinderColor: #eaf1ea; 
        hitCylinderHeight:0.1; 
        hitCylinderRadius: 0.1" 
        hand-controls="hand: left; 
        handModelStyle: lowPoly; 
        color: #909c9f"  
        position="" rotation="" scale="" visible="" 
        vive-controls="" 
        oculus-touch-controls="" 
        windows-motion-controls="" 
        gearvr-controls=""></a-entity>
        <!-- Right Controller -->
        <a-entity id="rightHand" hand-controls="hand: right; handModelStyle: lowPoly; color: #909c9f" laser-controls raycaster="showLine: true; far: 10; interval: 0; objects: .clickable, a-link;" line="color: #7cfc00; opacity: 0.5" visible="true"></a-entity>
    </a-entity>
   
    
    <!--Light.-->
        <a-light type="ambient" intensity="5" position="0 10 0"></a-light>
    </a-scene>
    </body>
</html>'''
        # ECRIT LES LIGNES D'ASSETS ET DE PLACEMENT
        for ob in f:
            result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/modelsXr/" + str(ob) + "\"></a-asset-item>") 
            
            result2 += "%s" % ("\n\t\t<a-entity gltf-model=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-entity>")
         
 
        for tele in g:
            result3 += "%s" % ("\n\t\t<a-asset-item id=\"" + str(tele)[:-4] + "-obj" + "\"" + " src=\"../asset/teleport/" + str(tele) + "\"></a-asset-item> ")
            
            result4 += "%s" % ("\n\t\t<a-entity obj-model=\"obj: " + "#" + str(tele)[:-4]+ "-obj;\" material=\"opacity: 0\" id=\"" + str(tele)[:-4] + "\" position=\"\" rotation=\"\" scale=\"1\"></a-entity>")
            
            result5 += "%s" % ("#" + str(tele)[:-4] + ", """) 
            
            
        result6 += "\n\t\t<a-sound src=\"" + "src: url(../sound/" + sound + ")\" loop autoplay=\"true\" position=\"0 2 5\"></a-sound>"
          
            
    
        filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\webxr\\', (projet) +  ".html")
        file = open(filename, "w", encoding="utf-8")
        file.write(a + projet + b + result + c + result3 + ctele + result6 + cplace + result2 + d + result4 + dtele + str(lireLien) + placeLien + result5 +dteleplace)
        file.close()
        return {'FINISHED'}
        


# WRITTEN THE CODE WEBXR  LINES FOR 6DOF HEADSETS FOR THE STREET THEATER
# ECRIT LES LIGNES DE CODE en WEBXR POUR LES CASQUES 6DOF RUE
class SIXDOFRUEXR_OT_SixdofRuexr(bpy.types.Operator):
    bl_idname = "object.sixdofruexr"
    bl_label = "Save html for headset (webXR) GLTF"
    bl_description = "Write file html webXR for headset 6DOF for road"
    
    def execute(self, context):
        projet = bpy.context.scene.my_tool.my_string
        dossier = bpy.context.scene.directory
        sound = bpy.context.scene.my_tool.my_string1
        selection = bpy.context.selected_objects
        result = ""
        result2 = ""
        result3 = ""
        result4 = ""
        result5 = ""
        result6 = ""
        
        # filtre les fichiers DAE pour les casques 6DOF dans le dossier "models" du dossier du projet
        extentions = ["glb"]
        e = [fn for fn in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\modelsXr\\') if fn.split(".")[-1] in extentions]
        newList = []
        for word in e:
            if not word.startswith('._'):
                newList.append(word)
                f = newList
        
        # filtre les fichiers obj pour les casques 6DOF dans le dossier "teleport" du dossier du projet           
        newExtentions = ["obj"]
        g = [fg for fg in os.listdir('' + (dossier) + '\\viewing\\' + (projet) + '\\asset\\teleport\\') if fg.split(".")[-1] in newExtentions]
        teleportList = []
        
        #recupere les liens vers d'autres expériences
        lienName = os.path.join ("" + (dossier) + "\\viewing\\" + (projet) + "\\asset\\link", "link.txt")
        with open (lienName) as fp:
            lireLien =fp.read()
            
        fp.close()

                          
        # Début page Html
        a = '''<html>
    <head>
    <title>'''
        b = '''</title>
    <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
    <script src="../../components/webxr/script/aframe-extras.min.js"></script>
    <script src="../../components/webxr/script/aframe-teleport-controls.js"></script>
    <!--The MIT License (MIT) Copyright (c) 2017 Fernando Serrano; Copyright (c) 2016 Don McCurdy -->
    </head>
    <body>
    
    <a-scene antialias="true">
    <!--Déclaration-->
        <a-assets>
        <!-- teleportation salle -->
        <a-asset-item id="leurreRue-obj" src="../../components/theatre/teleport/leurreRue.obj"></a-asset-item>
        
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS GENERE PAR BLENDER -->'''
        # ecriture des assets
        # suite page html
        c = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES ASSETS DE TELEPORTATIONS GENERE PAR BLENDER-->'''
        
        # ecriture des teleportations
        ctele = '''<!--Link-->
        <img id="sortie" src="../../components/webxr/link/sortie.jpg">
        </a-assets>
    <!--Fin Déclaration-->
    
        <!--image de fond.-->
        <a-sky color="black"></a-sky>
    
    
    <!--placement-->
    <!--sound-->'''
        #ecriture du son	

        cplace = '''\n\n\t\t<!-- teleportation salle -->
        <a-entity obj-model="obj: #leurreRue-obj;" material="opacity: 0" id="leurreRue" position="" rotation="" scale="1"></a-entity>
        
        <!--le decor-->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS GENERE PAR BLENDER -->'''
        # ecriture des placements
        
        d = '''\n\n\t\t<!-- teleportation plateau -->
        <!--A REMPLACER CI-DESSOUS LISTE DES PLACEMENTS DES TELEPORTATIONS GENERE PAR BLENDER -->'''
        
        # ecriture des placements de teleportations
        dtele = '''\n\n\t<!--Fin placement-->
    
    <!--Links-->
        <a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/webxr/menu.html" title=" " image="#sortie" position="7.56 2.5 1.22" rotation="0 90 0" scale="0.1 0.1 0.1"></a-link>
        <a-link href="https://www.scenographie-vr.com/webvr/vr1/viewing/menu/webxr/menu.html" title=" " image="#sortie" position="-7.58 2.5 1.39" rotation="0 -90 0" scale="0.1 0.1 0.1"></a-link>
      '''
            
        #placement des lien
            
        placeLien = '''  \n\t\t	
    <!-- Player -->
    <!-- camera -->
    <a-entity id="cameraRig">
        <a-entity id="head" camera wasd-controls look-controls></a-entity>
        
        <!-- gachette -->
        <!--A REMPLACER CI-DESSOUS collisioEntity par les cibles de téléportation-->
        <a-entity
        id="lefthand"
        teleport-controls="button: trigger; 
        cameraRig: #cameraRig; 
        teleportOrigin: #head;
        collisionEntities: '''
        
        #ecriture des teleportation dans le player
        dteleplace = '''#leurreRue;
        curveLineWidth: 0.01;
        curveHitColor: #eaf1ea;
        hitCylinderColor: #eaf1ea; 
        hitCylinderHeight:0.1; 
        hitCylinderRadius: 0.1" 
        hand-controls="hand: left; 
        handModelStyle: lowPoly; 
        color: #909c9f"
        position="" rotation="" scale="" visible="" 
        vive-controls="" 
        oculus-touch-controls="" 
        windows-motion-controls="" 
        gearvr-controls=""</a-entity>
        <!-- Right Controller -->
        <a-entity id="rightHand" hand-controls="hand: right; handModelStyle: lowPoly; color: #909c9f" laser-controls raycaster="showLine: true; far: 10; interval: 0; objects: .clickable, a-link;" line="color: #7cfc00; opacity: 0.5" visible="true"></a-entity>
    </a-entity>
    
    <!--Light.-->
        <a-light type="ambient" intensity="5" position="0 10 0"></a-light>
    </a-scene>
    </body>
</html>'''
        # ECRIT LES LIGNES D'ASSETS ET DE PLACEMENT
        for ob in f:
            result += "%s" % ("\n\t\t<a-asset-item id=\"" + str(ob)[:-4] + "\"" + " src=\"../asset/modelsXr/" + str(ob) + "\"></a-asset-item>") 
            
            result2 += "%s" % ("\n\t\t<a-entity gltf-model=\"" + "#" + str(ob)[:-4]+ "\"" + " position=\"0 0 0\"></a-entity>")
         
 
        for tele in g:
            result3 += "%s" % ("\n\t\t<a-asset-item id=\"" + str(tele)[:-4] + "-obj" + "\"" + " src=\"../asset/teleport/" + str(tele) + "\"></a-asset-item> ")
            
            result4 += "%s" % ("\n\t\t<a-entity obj-model=\"obj: " + "#" + str(tele)[:-4]+ "-obj;\" material=\"opacity: 0\" id=\"" + str(tele)[:-4] + "\" position=\"\" rotation=\"\" scale=\"1\"></a-entity>")
            
            
            result5 += "%s" % ("#" + str(tele)[:-4] + ", """)
        
        result6 += "\n\t\t<a-sound src=\"" + "src: url(../sound/" + sound + ")\" loop autoplay=\"true\" position=\"0 2 5\"></a-sound>"
    
            
                
         
        filename = os.path.join ('' + (dossier) + '\\viewing\\' + (projet) + '\\webxr\\', (projet) +  ".html")
        file = open(filename, "w", encoding="utf-8")
        file.write(a + projet + b + result + c + result3 + ctele + result6 + cplace + result2 + d + result4 + dtele + str(lireLien) + placeLien + result5 + dteleplace)
        file.close()
        return {'FINISHED'}
        




class VRTOOLS_PT_run(bpy.types.Panel):
    bl_category = "Tools"
    
    bl_label = "Vr Tools"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category  =  'VrTools'
    
    @classmethod
    def poll(self,context):
        return context.object is not None
    
    def draw(self, context):
        
        layout = self.layout
        layout.label(text="Create Folder", icon ="NEWFOLDER")
        
     
        self.layout.prop(context.scene, "directory")
        scene = context.scene
        
        mytool = scene.my_tool
        layout.prop(mytool, "my_string")
        
        row = layout.row()
        row.label(text="Create new Folders:")
        col = layout.column(align=True)
        row.operator("object.createfolder")
        row = layout.row()
        
        box = layout.box()
        layout.label(text="Create Bake Texture", icon ="ASSET_MANAGER")
        
        
        row = layout.row()
        row.label(text="Create new uvMap call uvBake")
        row.operator("object.uvbake")
        row = layout.row()
    
        row = layout.row()
        row.label(text="Unwrap all uvMap call uvBake")
        col = layout.column(align=True)
        row.operator("object.depliuvbake")
        row = layout.row()
    
        row = layout.row()
        row.label(text="Create image for Texture Bake")
        col = layout.column(align=True)
        row.operator("object.createimagebakelow")
   
    
        row = layout.row()
        row.label(text="")
        row.operator("object.createimagebakemedium")
        row = layout.row()
    
        row = layout.row()
        row.label(text="")
        row.operator("object.createimagebakehight")
        row = layout.row()
    
    
        row = layout.row()
        row.label(text="Create nodes Image Texture and uvMap")
        col = layout.column(align=True)
        row.operator("object.createnodebake")
        row = layout.row()
    
        row = layout.row()
        row.label(text="Bake selected object")
        col = layout.column(align=True)
        row.operator("object.baking")
        row = layout.row()
    
        row = layout.row()
        row.label(text="Put Texture Bake")
        row.operator("object.puttexture")
        row = layout.row()
        
        row = layout.row()
        box = layout.box()
        
        layout.label(text="File Writing", icon ="WORDWRAP_ON")
        row = layout.row()
        
        
        row = layout.row()
        row.label(text="Export Collada")
        row.operator("object.colladaexport")
        row.operator("object.colladaoneexport")
        col = layout.column(align=True)
        
        
        layout.label(text="Save teleport object in teleport's folder")
        row = layout.row()
        row.operator("object.teleportexport")
            
        col = layout.column(align=True)
        
        layout.label(text="Teleport Computer and smartphone")
        row = layout.row()
        row.operator("object.teleport")
        col = layout.column(align=True)
            
            
        row = layout.row()
        box = layout.box()
        
    
        layout.label(text="html writing for webVr", icon ="WORDWRAP_ON")
        row = layout.row()
        
        # choix theatre de rue
        sce = context.scene
        layout.prop(sce, "my_prop") 
        
        a = bpy.context.scene.my_prop 
        if a is False:   
    
           
        
            layout.label(text="Create html file for 6DOF headset")
            row = layout.row()
            row.operator("object.sixdofvr")
            
            
            col = layout.column(align=True)
            
            
            layout.label(text="Create html file for computer")
            row = layout.row()
            row.operator("object.computer")
    
            col = layout.column(align=True)
   
    
            layout.label(text="Create html file for smartphone")
            row = layout.row()
            row.operator("object.smartphone")
   
            col = layout.column(align=True)
            row = layout.row() 
            

            row = layout.row()
            box = layout.box()
            
            col = layout.column(align=True)
            row = layout.row() 
            
            layout.label(text="html writing for webXR", icon ="WORDWRAP_ON")
            row = layout.row()  
            
            layout.label(text="Create html file for 6DOF headset")
            row = layout.row()
            row.operator("object.sixdof")
                       
        
        else:
            layout.label(text="Create html file for 6DOF headset")
            row = layout.row()
            row.operator("object.sixdofruevr")
        
            col = layout.column(align=True)
  

            layout.label(text="Create html file for computer")
            row = layout.row()
            row.operator("object.computerrue")
    
            col = layout.column(align=True)
   
    
            layout.label(text="Create html file for smartphone")
            row = layout.row()
            row.operator("object.smartphonerue")
   
            col = layout.column(align=True)
            row = layout.row() 

            row = layout.row()
            box = layout.box()
        
            layout.label(text="html writing for webXR", icon ="WORDWRAP_ON")
            row = layout.row()
           
            layout.label(text="Create html file for 6DOF headset")
            row = layout.row()
            row.operator("object.sixdofrue")

 
classes = (
    CREATE_OT_createFolder,
    CREATE_OT_uvBake,
    DEPLI_OT_depliUvBake,
    CREA_OT_createImageBakeLow,
    CREA_OT_createImageBakeMedium,
    CREA_OT_createImageBakeHight,
    CREA_OT_createNodeBake,
    BAKE_OT_Baking,
    VRTOOLS_PT_run,
    NEWTEX_OT_putTexture,
    EXPORT_OT_ColladaExport,
    EXPORTONLY_OT_ColladaOneExport,
    TELEPORT_OT_TeleportExport,
    TELEPORTEMPTY_OT_Teleport,
    SIXDOF_OT_Sixdof,
    SIXDOFRUE_OT_SixdofRue,
    CARDBO_OT_smartphone,
    CARBORUEsmartphoneRue,
    ORDI_OT_Ordi,
    ORDI_OT_Ordirue,
    SIXDOF_OT_Sixdofvr,
    SIXDOFRUE_OT_SixdofRuevr,
    SIXDOFXR_OT_Sixdofxr,
    SIXDOFRUEXR_OT_SixdofRuexr,
    MySettings,
    )



def register():
    for cls in classes:
        bpy.utils.register_class(cls)
   
   
    bpy.types.Scene.my_tool = PointerProperty(type=MySettings)
    bpy.types.Scene.directory = StringProperty(subtype='DIR_PATH')

def unregister():
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)
      
    del (bpy.types.Scene.my_tool)
    del (bpy.types.Scene.directory)
if __name__ == "__main__":
    register()        
        
       
        
               
        
        
        
        
              
        
        
        



        










