From 02bf5a544c0c83299885b99b54b7eaca666cbe13 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 07:35:47 +0800 Subject: [PATCH 1/9] fix marshal bug --- server/test/json/primitive_d/primitive_d.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/test/json/primitive_d/primitive_d.go b/server/test/json/primitive_d/primitive_d.go index 010b2783..fd5cb467 100644 --- a/server/test/json/primitive_d/primitive_d.go +++ b/server/test/json/primitive_d/primitive_d.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "reflect" "unsafe" "go.mongodb.org/mongo-driver/bson/primitive" @@ -15,7 +16,7 @@ func main() { {Key: "hello", Value: "world"}, } - jsoniter.RegisterTypeEncoder("go.mongodb.org/mongo-driver/bson/primitive.D", PrimitiveDEncoder{}) + jsoniter.RegisterTypeEncoder(reflect.TypeOf(primitive.D{}).String(), PrimitiveDEncoder{}) bytes, err := jsoniter.Marshal(data) if err != nil { From f834d70eab7d40a061c6c84dc526f3c9b37648e9 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 07:38:55 +0800 Subject: [PATCH 2/9] fix marshal bug --- server/helper/json.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/helper/json.go b/server/helper/json.go index 38f2d44d..23aad4bd 100644 --- a/server/helper/json.go +++ b/server/helper/json.go @@ -8,19 +8,24 @@ package helper import ( + "reflect" + "time" + + "go.mongodb.org/mongo-driver/bson/primitive" + jsoniter "github.com/json-iterator/go" "github.com/tengge1/shadoweditor/helper/encoder" ) func init() { - jsoniter.RegisterTypeEncoder("time.Time", encoder.TimeEncoder{}) + jsoniter.RegisterTypeEncoder(reflect.TypeOf(time.Now()).String(), encoder.TimeEncoder{}) jsoniter.RegisterTypeEncoder( - "go.mongodb.org/mongo-driver/bson/primitive.ObjectID", + reflect.TypeOf(primitive.NewObjectID()).String(), encoder.PrimitiveObjectIDEncoder{}, ) jsoniter.RegisterTypeEncoder( - "go.mongodb.org/mongo-driver/bson/primitive.D", + reflect.TypeOf(primitive.D{}).String(), encoder.PrimitiveDEncoder{}, ) } From e740f2ad2ce955b5721aac3f36508bffdce90079 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 07:45:23 +0800 Subject: [PATCH 3/9] change log dir --- scripts/build.bat | 0 scripts/run.bat | 0 server/config.toml | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/build.bat mode change 100644 => 100755 scripts/run.bat diff --git a/scripts/build.bat b/scripts/build.bat old mode 100644 new mode 100755 diff --git a/scripts/run.bat b/scripts/run.bat old mode 100644 new mode 100755 diff --git a/server/config.toml b/server/config.toml index bae827e5..21f8096f 100644 --- a/server/config.toml +++ b/server/config.toml @@ -20,4 +20,4 @@ enabled = false # enable remote edit web_socket_port = 5000 # web socket server port [log] -file = "../logs/ShadowServer.txt" \ No newline at end of file +file = "./logs/ShadowServer.txt" \ No newline at end of file From 4c9ab76b5091a1cfda5320733f1168661fc37ee1 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 08:06:42 +0800 Subject: [PATCH 4/9] update config file --- server/config.toml | 12 +++++++++--- server/helper/config.go | 18 ++++++++++++++++-- server/helper/config_test.go | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/server/config.toml b/server/config.toml index 21f8096f..56ce9134 100644 --- a/server/config.toml +++ b/server/config.toml @@ -5,11 +5,12 @@ port = ":2020" # server address [database] type = "mongo" # only support mongo -connection = "mongodb://127.0.0.1:27017" # mongo connection string -database = "ShadowEditor" # mongo database name +host = "127.0.0.1" # mongoDB host +port = 27017 # mongoDB port +database = "ShadowEditor" # mongoDB database name [authority] -enabled = true # enable authority +enabled = true # enable authority expires = 120 # login time, minutes, only support integer [upload] @@ -19,5 +20,10 @@ max_size = 1000000000 # max upload file size enabled = false # enable remote edit web_socket_port = 5000 # web socket server port +[path] +public_dir = "./public" # The directory that contains index.html. +upload_dir = "./public/Upload" # The directory that user upload mesh, texture, etc. Need write authority. +log_dir = "./logs" # The directory that contains log files. Need write authority. + [log] file = "./logs/ShadowServer.txt" \ No newline at end of file diff --git a/server/helper/config.go b/server/helper/config.go index 4409579c..02c5c8a0 100644 --- a/server/helper/config.go +++ b/server/helper/config.go @@ -8,6 +8,7 @@ package helper import ( + "fmt" "os" "github.com/BurntSushi/toml" @@ -27,6 +28,8 @@ func GetConfig(path string) (config *ConfigModel, err error) { return nil, err } + config.Database.Connection = fmt.Sprintf("mongodb://%v:%v", config.Database.Host, config.Database.Port) + return } @@ -37,6 +40,7 @@ type ConfigModel struct { Authority AuthorityConfigModel `toml:"authority"` Upload UploadConfigModel `toml:"upload"` Remote RemoteConfigModel `toml:"remote"` + Path PathConfigModel `toml:"path"` Log LogConfigModel `toml:"log"` } @@ -47,8 +51,11 @@ type ServerConfigModel struct { // DatabaseConfigModel database config type DatabaseConfigModel struct { - Type string `toml:"type"` - Connection string `toml:"connection"` + Type string `toml:"type"` + Host string `toml:"host"` + Port int `toml:"port"` + // Connection should not read from config.toml. + Connection string Database string `toml:"database"` } @@ -69,6 +76,13 @@ type RemoteConfigModel struct { WebSocketPort int `toml:"web_socket_port"` } +// PathConfigModel is the path config. +type PathConfigModel struct { + PublicDir string `toml:"public_dir"` + UploadDir string `toml:"upload_dir"` + LogDir string `toml:"log_dir"` +} + // LogConfigModel log config type LogConfigModel struct { File string `toml:"file"` diff --git a/server/helper/config_test.go b/server/helper/config_test.go index 66fcd2df..a81383b9 100644 --- a/server/helper/config_test.go +++ b/server/helper/config_test.go @@ -29,5 +29,9 @@ func TestConfig(t *testing.T) { t.Logf("remote.enabled: %v", config.Remote.Enabled) t.Logf("remote.web_socket_port: %v", config.Remote.WebSocketPort) + t.Logf("path.public_dir: %v", config.Path.PublicDir) + t.Logf("path.upload_dir: %v", config.Path.UploadDir) + t.Logf("path.log_dir: %v", config.Path.LogDir) + t.Logf("log.file: %v", config.Log.File) } From 96cd17becdb0335c7acf84179a8e307b68a2580a Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 08:30:04 +0800 Subject: [PATCH 5/9] windows separator --- server/helper/config.go | 28 +++++++++++++++++++--------- server/test/system/check_type.go | 10 ++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 server/test/system/check_type.go diff --git a/server/helper/config.go b/server/helper/config.go index 02c5c8a0..2f087ace 100644 --- a/server/helper/config.go +++ b/server/helper/config.go @@ -10,11 +10,13 @@ package helper import ( "fmt" "os" + "runtime" + "strings" "github.com/BurntSushi/toml" ) -// GetConfig get config from config.toml +// GetConfig get server config from `config.toml` func GetConfig(path string) (config *ConfigModel, err error) { file, err := os.Open(path) if err != nil { @@ -28,12 +30,20 @@ func GetConfig(path string) (config *ConfigModel, err error) { return nil, err } + // parse mongoDB connection string. config.Database.Connection = fmt.Sprintf("mongodb://%v:%v", config.Database.Host, config.Database.Port) + // In windows system, path separator "/" should be replace with "\\". + if strings.HasPrefix(runtime.GOOS, "windows") { + config.Path.PublicDir = strings.ReplaceAll(config.Path.PublicDir, "/", "\\") + config.Path.UploadDir = strings.ReplaceAll(config.Path.UploadDir, "/", "\\") + config.Path.LogDir = strings.ReplaceAll(config.Path.LogDir, "/", "\\") + } + return } -// ConfigModel shadoweditor config +// ConfigModel is the structure of file `config.toml`. type ConfigModel struct { Server ServerConfigModel `toml:"server"` Database DatabaseConfigModel `toml:"database"` @@ -44,12 +54,12 @@ type ConfigModel struct { Log LogConfigModel `toml:"log"` } -// ServerConfigModel server config +// ServerConfigModel is the server config section in `config.toml`; type ServerConfigModel struct { Port string `toml:"port"` } -// DatabaseConfigModel database config +// DatabaseConfigModel is the database config section in `config.toml`; type DatabaseConfigModel struct { Type string `toml:"type"` Host string `toml:"host"` @@ -59,31 +69,31 @@ type DatabaseConfigModel struct { Database string `toml:"database"` } -// AuthorityConfigModel authority config +// AuthorityConfigModel is the authority config section in `config.toml`; type AuthorityConfigModel struct { Enabled bool `toml:"enabled"` Expires int `toml:"expires"` } -// UploadConfigModel upload config +// UploadConfigModel is the upload config section in `config.toml`; type UploadConfigModel struct { MaxSize int64 `toml:"max_size"` } -// RemoteConfigModel remote config +// RemoteConfigModel is the remote config section in `config.toml`; type RemoteConfigModel struct { Enabled bool `toml:"enabled"` WebSocketPort int `toml:"web_socket_port"` } -// PathConfigModel is the path config. +// PathConfigModel is the authority path section in `config.toml`; type PathConfigModel struct { PublicDir string `toml:"public_dir"` UploadDir string `toml:"upload_dir"` LogDir string `toml:"log_dir"` } -// LogConfigModel log config +// LogConfigModel is the log config section in `config.toml`; type LogConfigModel struct { File string `toml:"file"` } diff --git a/server/test/system/check_type.go b/server/test/system/check_type.go new file mode 100644 index 00000000..eeb13b1c --- /dev/null +++ b/server/test/system/check_type.go @@ -0,0 +1,10 @@ +package main + +import ( + "fmt" + "runtime" +) + +func main() { + fmt.Println(runtime.GOOS) +} From 90192402c7249ca846354e1c97b4cb2b66558865 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 09:01:51 +0800 Subject: [PATCH 6/9] move map path to server --- server/config.toml | 4 ++-- server/helper/config.go | 2 -- server/helper/config_test.go | 1 - server/server/animation/handle_animation.go | 4 ++-- server/server/audio/handle_audio.go | 4 ++-- server/server/export/editor/copy_assets.go | 10 +++++----- server/server/export/editor/run.go | 2 +- server/{helper => server}/map_path.go | 2 +- server/{helper => server}/map_path_test.go | 2 +- server/server/mesh/handle_mesh.go | 8 ++++---- .../crossorigin.go => middleware_crossorigin.go} | 2 +- .../server/{middleware/gzip.go => middleware_gzip.go} | 2 +- .../{middleware/static.go => middleware_static.go} | 6 ++---- server/server/screenshot/handle_screenshot.go | 4 ++-- server/server/server.go | 8 +++----- server/server/texture/handle_texture.go | 4 ++-- server/server/upload/handle_upload.go | 2 +- server/server/video/handle_video.go | 4 ++-- 18 files changed, 32 insertions(+), 39 deletions(-) rename server/{helper => server}/map_path.go (97%) rename server/{helper => server}/map_path_test.go (96%) rename server/server/{middleware/crossorigin.go => middleware_crossorigin.go} (96%) rename server/server/{middleware/gzip.go => middleware_gzip.go} (98%) rename server/server/{middleware/static.go => middleware_static.go} (91%) diff --git a/server/config.toml b/server/config.toml index 56ce9134..ac5ae14a 100644 --- a/server/config.toml +++ b/server/config.toml @@ -21,8 +21,8 @@ enabled = false # enable remote edit web_socket_port = 5000 # web socket server port [path] -public_dir = "./public" # The directory that contains index.html. -upload_dir = "./public/Upload" # The directory that user upload mesh, texture, etc. Need write authority. +public_dir = "./public" # The directory that contains index.html. + # Path `./public/Upload` need write authority. log_dir = "./logs" # The directory that contains log files. Need write authority. [log] diff --git a/server/helper/config.go b/server/helper/config.go index 2f087ace..363b542b 100644 --- a/server/helper/config.go +++ b/server/helper/config.go @@ -36,7 +36,6 @@ func GetConfig(path string) (config *ConfigModel, err error) { // In windows system, path separator "/" should be replace with "\\". if strings.HasPrefix(runtime.GOOS, "windows") { config.Path.PublicDir = strings.ReplaceAll(config.Path.PublicDir, "/", "\\") - config.Path.UploadDir = strings.ReplaceAll(config.Path.UploadDir, "/", "\\") config.Path.LogDir = strings.ReplaceAll(config.Path.LogDir, "/", "\\") } @@ -89,7 +88,6 @@ type RemoteConfigModel struct { // PathConfigModel is the authority path section in `config.toml`; type PathConfigModel struct { PublicDir string `toml:"public_dir"` - UploadDir string `toml:"upload_dir"` LogDir string `toml:"log_dir"` } diff --git a/server/helper/config_test.go b/server/helper/config_test.go index a81383b9..5381db75 100644 --- a/server/helper/config_test.go +++ b/server/helper/config_test.go @@ -30,7 +30,6 @@ func TestConfig(t *testing.T) { t.Logf("remote.web_socket_port: %v", config.Remote.WebSocketPort) t.Logf("path.public_dir: %v", config.Path.PublicDir) - t.Logf("path.upload_dir: %v", config.Path.UploadDir) t.Logf("path.log_dir: %v", config.Path.LogDir) t.Logf("log.file: %v", config.Log.File) diff --git a/server/server/animation/handle_animation.go b/server/server/animation/handle_animation.go index 88b84b83..c84fff34 100644 --- a/server/server/animation/handle_animation.go +++ b/server/server/animation/handle_animation.go @@ -166,7 +166,7 @@ func (Animation) Add(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/Animation/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) tempPath := filepath.Join(physicalPath, "temp") @@ -375,7 +375,7 @@ func (Animation) Delete(w http.ResponseWriter, r *http.Request) { } path := doc["SavePath"].(string) - physicalPath := helper.MapPath(path) + physicalPath := server.MapPath(path) os.RemoveAll(physicalPath) db.DeleteOne(server.AnimationCollectionName, filter) diff --git a/server/server/audio/handle_audio.go b/server/server/audio/handle_audio.go index fb891f48..2e0f4405 100644 --- a/server/server/audio/handle_audio.go +++ b/server/server/audio/handle_audio.go @@ -166,7 +166,7 @@ func (Audio) Add(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/Audio/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) if _, err := os.Stat(physicalPath); os.IsNotExist(err) { os.MkdirAll(physicalPath, 0755) @@ -343,7 +343,7 @@ func (Audio) Delete(w http.ResponseWriter, r *http.Request) { } path := doc["SavePath"].(string) - physicalPath := helper.MapPath(path) + physicalPath := server.MapPath(path) os.RemoveAll(physicalPath) db.DeleteOne(server.AudioCollectionName, filter) diff --git a/server/server/export/editor/copy_assets.go b/server/server/export/editor/copy_assets.go index 13feb985..45fa4fc8 100644 --- a/server/server/export/editor/copy_assets.go +++ b/server/server/export/editor/copy_assets.go @@ -19,7 +19,7 @@ import ( // CopyAssets copy the assets needed to the exported scene. func CopyAssets(path string) error { // copy html files - sourceName := helper.MapPath("/index.html") + sourceName := server.MapPath("/index.html") destName := filepath.Join(path, "editor.html") if err := helper.CopyFile(sourceName, destName); err != nil { return err @@ -41,28 +41,28 @@ func CopyAssets(path string) error { os.MkdirAll(dirName, 0755) } - sourceName = helper.MapPath("/build/ShadowEditor.js") + sourceName = server.MapPath("/build/ShadowEditor.js") destName = filepath.Join(path, "build", "ShadowEditor.js") if err := helper.CopyFile(sourceName, destName); err != nil { return err } // copy assets folder - sourceName = helper.MapPath("/assets") + sourceName = server.MapPath("/assets") destName = filepath.Join(path, "assets") if err := helper.CopyDirectory(sourceName, destName); err != nil { return err } // copy language pack - sourceName = helper.MapPath("/lang") + sourceName = server.MapPath("/lang") destName = filepath.Join(path, "lang") if err := helper.CopyDirectory(sourceName, destName); err != nil { return err } // copy website icon - sourceName = helper.MapPath("/favicon.ico") + sourceName = server.MapPath("/favicon.ico") destName = filepath.Join(path, "favicon.ico") return helper.CopyDirectory(sourceName, destName) } diff --git a/server/server/export/editor/run.go b/server/server/export/editor/run.go index 7e86eb1c..5d9e3ba2 100644 --- a/server/server/export/editor/run.go +++ b/server/server/export/editor/run.go @@ -26,7 +26,7 @@ func init() { func Run(w http.ResponseWriter, r *http.Request) { now := time.Now() - path := helper.MapPath(fmt.Sprintf("/temp/%v", helper.TimeToString(now, "yyyyMMddHHmmss"))) + path := server.MapPath(fmt.Sprintf("/temp/%v", helper.TimeToString(now, "yyyyMMddHHmmss"))) if _, err := os.Stat(path); os.IsNotExist(err) { os.MkdirAll(path, 0755) diff --git a/server/helper/map_path.go b/server/server/map_path.go similarity index 97% rename from server/helper/map_path.go rename to server/server/map_path.go index bb52f9bb..8b8c2278 100644 --- a/server/helper/map_path.go +++ b/server/server/map_path.go @@ -5,7 +5,7 @@ // For more information, please visit: https://github.com/tengge1/ShadowEditor // You can also visit: https://gitee.com/tengge1/ShadowEditor -package helper +package server import ( "fmt" diff --git a/server/helper/map_path_test.go b/server/server/map_path_test.go similarity index 96% rename from server/helper/map_path_test.go rename to server/server/map_path_test.go index 72d813d3..c560cf2a 100644 --- a/server/helper/map_path_test.go +++ b/server/server/map_path_test.go @@ -5,7 +5,7 @@ // For more information, please visit: https://github.com/tengge1/ShadowEditor // You can also visit: https://gitee.com/tengge1/ShadowEditor -package helper +package server import "testing" diff --git a/server/server/mesh/handle_mesh.go b/server/server/mesh/handle_mesh.go index 4532177c..c9fa57cb 100644 --- a/server/server/mesh/handle_mesh.go +++ b/server/server/mesh/handle_mesh.go @@ -169,7 +169,7 @@ func (Mesh) Add(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/Model/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) tempPath := filepath.Join(physicalPath, "temp") @@ -540,7 +540,7 @@ func (Mesh) Delete(w http.ResponseWriter, r *http.Request) { } path := doc["SavePath"].(string) - physicalPath := helper.MapPath(path) + physicalPath := server.MapPath(path) os.RemoveAll(physicalPath) db.DeleteOne(server.MeshCollectionName, filter) @@ -588,11 +588,11 @@ func (Mesh) Download(w http.ResponseWriter, r *http.Request) { } // create zip file - savePath := helper.MapPath(doc["SavePath"].(string)) + savePath := server.MapPath(doc["SavePath"].(string)) now := helper.TimeToString(time.Now(), "yyyyMMddHHmmssfff") destFile := fmt.Sprintf("/temp/%v.zip", now) - descPhysicalFile := helper.MapPath(destFile) + descPhysicalFile := server.MapPath(destFile) helper.Zip(savePath, descPhysicalFile) diff --git a/server/server/middleware/crossorigin.go b/server/server/middleware_crossorigin.go similarity index 96% rename from server/server/middleware/crossorigin.go rename to server/server/middleware_crossorigin.go index 33ab37fc..d6e4635d 100644 --- a/server/server/middleware/crossorigin.go +++ b/server/server/middleware_crossorigin.go @@ -5,7 +5,7 @@ // For more information, please visit: https://github.com/tengge1/ShadowEditor // You can also visit: https://gitee.com/tengge1/ShadowEditor -package middleware +package server import ( "net/http" diff --git a/server/server/middleware/gzip.go b/server/server/middleware_gzip.go similarity index 98% rename from server/server/middleware/gzip.go rename to server/server/middleware_gzip.go index 07e56982..ac891c1c 100644 --- a/server/server/middleware/gzip.go +++ b/server/server/middleware_gzip.go @@ -5,7 +5,7 @@ // For more information, please visit: https://github.com/tengge1/ShadowEditor // You can also visit: https://gitee.com/tengge1/ShadowEditor -package middleware +package server import ( "compress/gzip" diff --git a/server/server/middleware/static.go b/server/server/middleware_static.go similarity index 91% rename from server/server/middleware/static.go rename to server/server/middleware_static.go index 8d41dbb9..96eb9cf9 100644 --- a/server/server/middleware/static.go +++ b/server/server/middleware_static.go @@ -5,7 +5,7 @@ // For more information, please visit: https://github.com/tengge1/ShadowEditor // You can also visit: https://gitee.com/tengge1/ShadowEditor -package middleware +package server import ( "fmt" @@ -15,8 +15,6 @@ import ( "os" "path/filepath" "strings" - - "github.com/tengge1/shadoweditor/helper" ) // StaticHandler is responsible for serve static contents. @@ -29,7 +27,7 @@ func StaticHandler(w http.ResponseWriter, r *http.Request, next http.HandlerFunc // TODO: May have security risk. // static contents - path := helper.MapPath("/public/") + r.URL.Path + path := MapPath("/public/") + r.URL.Path if strings.HasSuffix(path, "/") { path += "index.html" diff --git a/server/server/screenshot/handle_screenshot.go b/server/server/screenshot/handle_screenshot.go index abb15772..add91418 100644 --- a/server/server/screenshot/handle_screenshot.go +++ b/server/server/screenshot/handle_screenshot.go @@ -169,7 +169,7 @@ func (Screenshot) Add(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/Screenshot/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) if _, err := os.Stat(physicalPath); os.IsNotExist(err) { os.MkdirAll(physicalPath, 0755) @@ -345,7 +345,7 @@ func (Screenshot) Delete(w http.ResponseWriter, r *http.Request) { } path := doc["SavePath"].(string) - physicalPath := helper.MapPath(path) + physicalPath := server.MapPath(path) os.RemoveAll(physicalPath) db.DeleteOne(server.ScreenshotCollectionName, filter) diff --git a/server/server/server.go b/server/server/server.go index 76698fc3..e81dc9f4 100644 --- a/server/server/server.go +++ b/server/server/server.go @@ -12,8 +12,6 @@ import ( "net/http" "github.com/urfave/negroni" - - "github.com/tengge1/shadoweditor/server/middleware" ) // Start start the server @@ -21,9 +19,9 @@ func Start() { log.Printf("starting shadoweditor server on port %v", Config.Server.Port) handler := negroni.Classic() - handler.Use(negroni.HandlerFunc(middleware.CrossOriginHandler)) - handler.Use(negroni.HandlerFunc(middleware.GZipHandler)) - // handler.Use(negroni.HandlerFunc(middleware.StaticHandler)) + handler.Use(negroni.HandlerFunc(CrossOriginHandler)) + handler.Use(negroni.HandlerFunc(GZipHandler)) + handler.Use(negroni.HandlerFunc(StaticHandler)) handler.UseHandler(Mux) err := http.ListenAndServe(Config.Server.Port, handler) diff --git a/server/server/texture/handle_texture.go b/server/server/texture/handle_texture.go index 1b6b0f0d..3b9ceb6e 100644 --- a/server/server/texture/handle_texture.go +++ b/server/server/texture/handle_texture.go @@ -183,7 +183,7 @@ func (Texture) Add(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/Texture/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) if _, err := os.Stat(physicalPath); os.IsNotExist(err) { os.MkdirAll(physicalPath, 0755) @@ -406,7 +406,7 @@ func (Texture) Delete(w http.ResponseWriter, r *http.Request) { // 删除纹理所在目录 path := doc["SavePath"].(string) - physicalPath := helper.MapPath(path) + physicalPath := server.MapPath(path) err = os.RemoveAll(physicalPath) if err != nil { diff --git a/server/server/upload/handle_upload.go b/server/server/upload/handle_upload.go index 4327aba6..e42ae3a0 100644 --- a/server/server/upload/handle_upload.go +++ b/server/server/upload/handle_upload.go @@ -67,7 +67,7 @@ func (Upload) Upload(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/File/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) if _, err := os.Stat(physicalPath); os.IsNotExist(err) { os.MkdirAll(physicalPath, 0755) diff --git a/server/server/video/handle_video.go b/server/server/video/handle_video.go index fd3ff5a8..a3df67c2 100644 --- a/server/server/video/handle_video.go +++ b/server/server/video/handle_video.go @@ -167,7 +167,7 @@ func (Video) Add(w http.ResponseWriter, r *http.Request) { now := time.Now() savePath := fmt.Sprintf("/Upload/Video/%v", helper.TimeToString(now, "yyyyMMddHHmmss")) - physicalPath := helper.MapPath(savePath) + physicalPath := server.MapPath(savePath) if _, err := os.Stat(physicalPath); os.IsNotExist(err) { os.MkdirAll(physicalPath, 0755) @@ -343,7 +343,7 @@ func (Video) Delete(w http.ResponseWriter, r *http.Request) { } path := doc["SavePath"].(string) - physicalPath := helper.MapPath(path) + physicalPath := server.MapPath(path) os.RemoveAll(physicalPath) db.DeleteOne(server.VideoCollectionName, filter) From 6b2056a8e2d9e72948bafcf45bb78d3750c9dc57 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 09:06:46 +0800 Subject: [PATCH 7/9] modity mappath --- server/server/map_path.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/server/map_path.go b/server/server/map_path.go index 8b8c2278..be07a4bd 100644 --- a/server/server/map_path.go +++ b/server/server/map_path.go @@ -18,6 +18,6 @@ func MapPath(path string) string { if !strings.HasPrefix(path, "/") { path = "/" + path } - path = strings.ReplaceAll(path, "/", string(filepath.Separator)) - return fmt.Sprintf("./%v", path) + path = fmt.Sprintf("%v%v", Config.Path.PublicDir, path) + return strings.ReplaceAll(path, "/", string(filepath.Separator)) } From 6a960fea6db7a7f2051aa793c2eeeae250886b68 Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 10:03:23 +0800 Subject: [PATCH 8/9] update readme --- README_zh.md | 173 ++++++++++++++++++++++++++---------------- server/cmd/version.go | 2 +- 2 files changed, 107 insertions(+), 68 deletions(-) diff --git a/README_zh.md b/README_zh.md index 2dcd3d37..ff2cb74a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -2,19 +2,17 @@ Supported Languages: 中文 / [English](README.md) / 日本語 / 한국어 / русский / Le français -> [点击此处](../../tree/v0.4.6-csharp/)切换到C#分支。 +> [点击此处](../../tree/v0.4.6-csharp/)切换到`C#`分支。 * 名称:Shadow Editor * 版本:v0.5.0(开发中) * 简介:基于`three.js`的场景编辑器。 * 源码:[GitHub](https://github.com/tengge1/ShadowEditor) [Gitee](https://gitee.com/tengge1/ShadowEditor) | 文档:[GitHub](https://tengge1.github.io/ShadowEditor/) [Gitee](https://tengge1.gitee.io/shadoweditor/) | 示例:[GitHub](https://tengge1.github.io/ShadowEditor-examples/) [Gitee](http://tengge1.gitee.io/shadoweditor-examples/) | 视频:[微博](https://weibo.com/tv/v/IjIn9AyvX?fid=1034:4446986821107725) [Bilibili](https://www.bilibili.com/video/av78428475?from=search&seid=9203731141485399611) | 资源:[百度云](https://pan.baidu.com/s/1IxJVM6fFLoIAJG-GKHjVTA) -* 技术栈:`html`、`css`、`javascript`、`rollup`、`react.js`、`webgl`、`three.js`、`asp.net`。 +* 技术栈:`html`、`css`、`javascript`、`rollup`、`react.js`、`webgl`、`three.js`、`golang`。 * 如果对您有帮助,请[【捐赠】](https://gitee.com/tengge1/ShadowEditor)支持项目发展,谢谢。 ## v0.5.0即将更新 -Go语言服务端已经开发完成,正在努力测试中,预计5月1日发布。 - 跟`asp.net`相比,`go语言服务端`具有非常多的好处: 1. 兼容`Windows`、`Linux`、`Mac`三大操作系统。 @@ -86,65 +84,136 @@ Go语言服务端已经开发完成,正在努力测试中,预计5月1日发 27. 自带字体管理器、转换器工具,可以将ttf字体文件转换为json文件,便于创建三维文字。 28. 支持设置选中颜色和边框粗细、鼠标高亮颜色,阴影类型,各种帮助器显示隐藏,滤镜效果,天气效果。 -## 使用指南 +## 开发需求 -**该项目仅支持Windows系统,电脑上需要安装.Net Framework 4.7.2及更新版本。** +**这些要求仅在开发编译时需要,运行环境不需要除了MongoDB和浏览器以外的其他软件。** -**兼容火狐和谷歌浏览器,推荐使用最新版谷歌浏览器。** +1. Windows, Linux, Mac, 或者任意支持`golang`和`nodejs`的系统。 +2. Golang 1.14.2+ +3. NodeJS 14.1+ +4. gcc 9.3.0+ (windows上需要安装`MinGW`并添加环境变量,保证`gcc`可以通过命令行访问)。 +5. git 2.25.1+ +6. MongoDB v3.6.8+ +7. VSCode 1.44.2+ +8. Chrome 81.0+ 或者 Firefox 75.0+ -1. 安装`NodeJs`,在最外层目录(有`README.md`文件的那个文件),执行以下命令。 +说明:低版本也可能支持,仅供参考。请在编译前安装好这些开发环境。 + +## 下载和编译 + +1. 下载代码。 ```bash -npm install -npm run build +git clone https://github.com/tengge1/ShadowEditor.git ``` -2. 下载`MongoDB`,安装并启动MongoDB服务。MongoDB服务的默认端口为27017。 - -MongoDB下载地址:https://www.mongodb.com/download-center/community - -可以下载zip版本,然后在MongoDB的bin文件夹执行以下命令安装服务,注意修改路径。 +由于国内`github`比较慢,可以使用gitee。 ```bash -mongod --dbpath=D:\mongodb\db --logpath=D:\mongodb\log\mongoDB.log --install --serviceName MongoDB -net start MongoDB +git clone https://gitee.com/tengge1/ShadowEditor.git ``` -3. 编辑文件`ShadowEditor.Web/Web.config`,将`27017`修改为你电脑上MongoDB服务的端口。 - -```xml - -``` - -4. 使用`Visual Studio 2017`打开项目,生成`ShadowEditor.Web`项目。 - -5. 将`ShadowEditor.Web`部署在iis上即可在浏览器中访问。 - -注意:发布网站部署,Web目录外面需要多加一层文件夹,用于存放日志、数据库备份等不能公开的资源。 - -6. 编译文档,请安装gitbook。 +如果你需要`C#`版本,可以切换到`C#`分支,但是该版本不再维护。 ```bash -npm install -g gitbook-cli +git checkout -b csharp origin/v0.4.6-csharp ``` -然后切换到`docs-dev`目录,安装gitbook插件。 +2. 下载安装`VSCode`,并安装`Go`扩展。 + +推荐安装以下扩展,但不是必须的。 + +`Shader languages support for VS Code`, `C/C++`, `ESLint`, `Go`, `TOML Language Support`. + +3. 国内用户设置`golang`和`nodejs`代理。 + +在国内,由于`golang.org`无法访问,`github.com`和`npmjs.com`特别慢,推荐设置代码。 + +Windows系统执行 ```bash -gitbook install +.\scripts\set_go_proxy.bat +.\scripts\set_npm_proxy.bat ``` -然后切换到上级目录,执行以下命令生成文档。 +Linux系统执行 ```bash -npm run docs +./scripts/set_go_proxy.sh +./scripts/set_npm_proxy.sh ``` +4. 安装`golang`开发常用的工具,具有智能提示、转到定义等功能。 + +Windows系统执行 + +```bash +.\scripts\install_develop.bat +``` + +Linux系统执行 + +```bash +./scripts/install_develop.sh +``` + +5. 安装`golang`和`nodejs`所需的第三方依赖。 + +Windows系统执行 + +```bash +.\scripts\install.bat +``` + +Linux系统执行 + +```bash +./scripts/install.sh +``` + +6. 编译`golang`和`nodejs`。 + +Windows系统执行 + +```bash +.\scripts\build.bat +``` + +Linux系统执行 + +```bash +./scripts/build.sh +``` + +编译的代码位于`build`文件夹中。发布时,只需要发布该文件夹即可。 + +7. 启动程序。 + +Windows系统执行 + +```bash +.\scripts\run.bat +``` + +Linux系统执行 + +```bash +./scripts/run.sh +``` + +命令行输出 + +``` +2020/05/02 09:57:20 starting shadoweditor server on port :2020 +``` + +这时,就可以在浏览器中访问了:http://localhost:2020 + ## 常见问题 1. 上传模型时为什么都是上传失败? -需要把模型贴图等资源压缩成一个zip包,而且入口文件不能嵌套文件夹。服务端会解压上传的zip包放到`~/Upload/Model`文件下,并在MongoDB `_Mesh`表里添加一条数据。 +需要把模型贴图等资源压缩成一个zip包,而且入口文件不能嵌套文件夹。服务端会解压上传的zip包放到`./public/Upload/Model`文件下,并在MongoDB `_Mesh`表里添加一条数据。 2. 如何将多个模型组合在一起? @@ -152,43 +221,13 @@ npm run docs 3. 如何开启权限系统? -打开`ShadowEditor.Web/Web.config`文件,将`EnableAuthority`设置为`true`。默认管理员用户名是`admin`,密码是`123456`。 +打开`config.toml`文件,将`authority.enabled`设置为`true`。默认管理员用户名是`admin`,密码是`123456`。 4. 前端报`asm.js 已被禁用,因为脚本调试程序已连接。请断开调试程序的连接,以启用 asm.js。`的错误。 **完整错误**:asm.js 已被禁用,因为脚本调试程序已连接。请断开调试程序的连接,以启用 asm.js。 ammo.js (1,1) SCRIPT1028: SCRIPT1028: Expected identifier, string or number ShadowEditor.js (3948,8) SCRIPT5009: 'Shadow' is not defined。 **解决方法**:腾讯浏览器不支持使用`Emscripten`编译的`ammo.js`(WebAssembly),建议换成谷歌浏览器。 -5. 前端报`404.0 - Not Found您要找的资源已被删除、已更名或暂时不可用。`的错误。 - -可能原因1:**iis没有开启asp.net支持。** - -解决方法: -1、打开控制面板、程序和功能、启用或关闭Windows功能。 -2、把`.NET Framework`勾选上。 -3、把Internet Information Services、万维网服务、应用程序开发功能,下面的`.NET Extensibility`、`ASP.NET`、`ISAPI扩展`、`ISAPI筛选器`、`应用程序初始化`勾选上,确定。 - -可能原因2:**服务端没有编译。** - -解决方法: -使用`Visual Studio 2017`打开项目,在解决方案管理器`ShadowEditor.Web`项目上右键,选择重新生成。 - -6. 上传模型报`对路径“C:\inetpub\wwwroot\Upload\Model\20200208192356\temp”的访问被拒绝。`的错误。 - -原因:`Upload`文件夹没有写入权限。 -解决方法: -右键`Upload`文件夹,点击属性。安全选项卡,点高级,添加。选择主体,填写Everyone,基本权限,选择`完全控制`就好了。 - -7. 发布场景后没反应。 - -1、看一下谷歌浏览器地址栏右侧,弹出窗口是不是被拦截了。 -2、打开开发者工具,看一下`Console`或`Network`选项卡,是不是报错了。 -3、发布的场景在`ShadowEditor.Web\temp`目录下,看一下有没有。 - -8. 将.net framework升级到4.7.2报错:未能找到文件`E:\github\ShadowEditor\ShadowEditor.Web\bin\roslyn\csc.exe`。 - -解决方法:清理解决方案,重新生成解决方案即可。 - ## 相关链接 * Three.js官网:https://threejs.org/ diff --git a/server/cmd/version.go b/server/cmd/version.go index c5dfaf37..545e8fb9 100644 --- a/server/cmd/version.go +++ b/server/cmd/version.go @@ -22,6 +22,6 @@ var versionCmd = &cobra.Command{ Short: "Print the version number of ShadowEditor", Long: `All software has versions. This is ShadowEditor's`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("ShadowEditor version: v0.4.6") + fmt.Println("ShadowEditor version: v0.5.0") }, } From 695142e45b5ce218b2758446a1c359756fe815bd Mon Sep 17 00:00:00 2001 From: tengge <930372551@qq.com> Date: Sat, 2 May 2020 10:31:19 +0800 Subject: [PATCH 9/9] update readme --- README.md | 225 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 131 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index 938960b9..696c07d6 100644 --- a/README.md +++ b/README.md @@ -2,32 +2,30 @@ Supported Languages: [中文](README_zh.md) / English / 日本語 / 한국어 / русский / Le français -> [Click here] (../../tree/v0.4.6-csharp/) to switch to the `C#` branch. +> [Click Here] (../../tree/v0.4.6-csharp/) to switch to `C#` branch. * Name: Shadow Editor * Version: v0.5.0 (under development) -* Introduction: Scene editor based on `three.js`. -* Source code: [GitHub](https://github.com/tengge1/ShadowEditor) [Gitee](https://gitee.com/tengge1/ShadowEditor) | Document: [GitHub](https://tengge1.github.io/ShadowEditor/) [Gitee](https://tengge1.gitee.io/shadoweditor/) | Example: [GitHub](https://tengge1.github.io/ShadowEditor-examples/) [Gitee](http: //tengge1.gitee.io/shadoweditor-examples/) | Video: [Weibo](https://weibo.com/tv/v/IjIn9AyvX?fid=1034:4446986821107725) [Bilibili](https://www.bilibili.com/video/av78428475?from=search&seid=9203731141485399611) | Resources: [Baidu Cloud](https://pan.baidu.com/s/1IxJVM6fFLoIAJG-GKHjVTA) -* Technology stack: `html`,` css`, `javascript`,` rollup`, `react.js`,` webgl`, `three.js`,` golang`. -* If it is helpful to you, please [donate](https://gitee.com/tengge1/ShadowEditor) to support the project development, thank you. +* Description: 3D scene editor based on `three.js`、`golang` and `mongoDB`. +* Source Code: [GitHub] (https://github.com/tengge1/ShadowEditor) [Gitee] (https://gitee.com/tengge1/ShadowEditor) | Document: [GitHub] (https://tengge1.github.io/ShadowEditor/) [Gitee](https://tengge1.gitee.io/shadoweditor/) | Demo: [GitHub] (https://tengge1.github.io/ShadowEditor-examples/) [Gitee] (http://tengge1.gitee.io/shadoweditor-examples/) | Video: [Weibo](https://weibo.com/tv/v/IjIn9AyvX?fid=1034:4446986821107725) [Bilibili] (https://www.bilibili.com/video/av78428475?from=search&seid=9203731141485399611) | Resources: [Baidu Cloud](https://pan.baidu.com/s/1IxJVM6fFLoIAJG-GKHjVTA) +* Technology Stack: `html`, ` css`, `javascript`, `rollup`, `react.js`, `webgl`, `three.js`, `golang`, `mongoDB`. +* If it is helpful to you, please [donate](https://gitee.com/tengge1/ShadowEditor) to support the development, thank you. -## v0.5.0 will be coming soon +## v0.5.0 is coming soon -The Go language server has been developed and is being tested, and is expected to be released on May 1. +Compared with `asp.net`, `golang` has many advantages: -Compared with `asp.net`,` go language server` has many advantages: - -1. Compatible with the three major operating systems of `Windows`,` Linux` and `Mac`. -2. Compiled language (similar to C language), supporting `goroutine`, which can give full play to the advantages of` CPU` multi-core and high performance. -3. Simple and easy to learn, abundant standard libraries and third-party libraries, and high development efficiency. -4. Can be compiled into a single executable file, users do not need to install `go language development environment`, nor do they need to install` NodeJs`. -5. You no longer need `iis`, you can use it by double-clicking, and you can achieve the unification of` desktop version` and `Web version`. +1. Compatible with both `Windows`, `Linux` and `Mac`. +2. Compiled language (similar to C language), supporting `goroutine`, which can take advantages of `CPU` multi-core and high performance. +3. Easy to learn. Huge standard libraries and third-party libraries, and high development efficiency. +4. Can be compiled into a single executable file, it is essential for users to install `golang` nor `NodeJs`. +5. No longer need `iis`, you can use it by double-clicking, and you can build both desktop and web version. 6. The returned data is enabled with `gzip` compression, the network data is reduced by more than 10 times, and the speed of displaying and loading scenes is greatly improved. 7. Development no longer requires the installation of a huge `Visual Studio`, no longer requires` Windows`, and a simple `Visual Studio Code` can be used to comfortably develop the front and back ends. -** Update log: ** +**Update log:** -1. Fixed the bug that the `draco` model could not be loaded due to the upgrade of` three.js`. +1. Fixed the bug that the `draco` model could not be loaded due to the upgrade of `three.js`. 2. Models in `.json` format are no longer supported. 3. Fix the bug that the bottom row of the category list window is blocked by the button. 4. Fix the bug that the texture resource cannot be loaded when the texture is attached. @@ -37,12 +35,12 @@ Compared with `asp.net`,` go language server` has many advantages: 8. Fixed the bug that the confirmation dialog could not be cancelled and closed. 9. Fixed the bug that the role is deleted and the list is not refreshed. -## v0.4.6Update [Update Log](docs-dev/update/UpdateLog.md) +## v0.4.6Update 【[Update Logs](docs-dev/update/UpdateLog.md)】 * Release date: April 5, 2020 * Update log: -1. Fixed the bug that the confirmation dialog of loading auto save scene could not be cancelled, the button of `Cancel` was changed to `Empty` +1. Fixed the bug that the confirmation dialog of loading auto save scene could not be cancelled, the button of `Cancel` was changed to` Empty`. 2. Fix the error of saving the sample scene report "ID is invalid". Now the sample scene can be saved normally. 3. Fix the bug of adding "background music" component as soon as you open the page. 4. Fixed the bug that the music file was not exported when the background music component was released. @@ -51,15 +49,15 @@ Compared with `asp.net`,` go language server` has many advantages: 7. Go language server. (In development) 8. Fix the bug that calling `clock.getDelta` and` clock.getElapsedTime` multiple times in the script causes abnormal animation. Now these two functions can be called multiple times in the script. -## Project screenshot +## Screenshot ![image](images/scene20200301.jpg) -## The main function +## Features 1. Based on three.js / WebGL 3D scene online editor, use `MongoDB` to save scenes, models, textures, materials, audio, animations, screenshots, video data, and support one-click database backup function. 2. Built-in objects: group, plane, cube, circle, cylinder, sphere, icosahedron, tire, knot, teapot, wine glass, unscaled text, 3D text, line segment, CatmullRom curve, quadratic Bezier curve, Cubic Bezier curve, elliptic curve, point label, sprite. -3. Built-in light source: ambient light, parallel light, point light source, spotlight, hemispherical light, rectangular light, comes with point light source helper (halo effect), hemispherical light helper (sky ball), rectangular light helper (screen ). +3. Built-in light sources: ambient light, parallel light, point light source, spotlight, hemispherical light, rectangular light, with point light source helper (halo effect), hemispherical light helper (sky ball), rectangular light helper (screen ). 4. Supports importing models and animations in many different 3D formats. Supports `3ds`,` 3mf`, `amf`,` assimp` (anim), `awd`,` babylon`, `binary`,` bvh` (anim), `collada`,` ctm`, `draco` , `Fbx` (anim),` gcode`, `gltf` (anim),` js` (anim), `json` (anim),` kmz`, `lmesh` (anim),` md2`, `mmd `(anim),` nrrd`, `obj`,` pcd`, `pdb`,` ply`, `prwm`,` sea3d` (anim), `stl`,` vrm`, `vrml`,` vtk `,` X` 31 kinds of 3D file formats, with `anim` means support animation. Multiple 3D files support both `json` and binary formats. The `mmd` file supports both` pmd` and `pmx` formats, and models and camera animations in the` vmd` format. It is also the only editor that supports `lmesh` (lolking website lol model). 5. Built-in materials: line material, dashed material, basic material, depth material, normal vector material, Lambert material, Feng's material, point cloud material, standard material, physical material, sprite material, shader material, original shader Material. 6. Support textures: color texture, transparent texture, bump texture, normal texture, displacement texture, mirror texture, environment texture, lighting texture, occlusion texture, self-illumination texture. @@ -74,7 +72,7 @@ Compared with `asp.net`,` go language server` has many advantages: 15. Support lattice effect, color shift effect, afterimage effect, background blur, fast approximate anti-aliasing (FXAA), glitch effect, halftone effect, full-screen anti-aliasing (SSAA), pixel effect, scalable ambient light Occlusion (SAO), multi-sample anti-aliasing (SMAA), screen space ambient occlusion (SSAO), temporal anti-aliasing (TAA). 16. Provide history and log functions, support undo and redo. 17. Support exporting `gltf`,` obj`, `ply`,` stl`, `Collada`,` DRACO` scenes and models. -18. Support `bullet` physics engine. Cubes, circles, cylinders, icosahedrons, wine glasses, planes, spheres, teapots, tires, knots, and loaded models all support rigid body components. Support visual setting of collider shape (cube, sphere), mass and inertia. +18. Support `bullet` physics engine. Cubes, circles, cylinders, icosahedrons, wine glasses, planes, spheres, teapots, tires, knots and loaded models all support rigid body components. Support visual setting of collider shape (cube, sphere), mass and inertia. 19. It has tools for translation, rotation, scaling, drawing points, lines, and decals on the surface of objects, and real-time statistics of the number of objects, vertices, and triangles in the scene. 20. Support scene publishing function, which can publish scenes as static resources and deploy to any server. 21. Built-in languages ​​of the software: `Chinese`,` Traditional Chinese`, `English`,` 日本语 `,` 한국어 `,` русский`, `Le français`. @@ -86,115 +84,154 @@ Compared with `asp.net`,` go language server` has many advantages: 27. Comes with font manager and converter tool, which can convert ttf font file to json file, which is convenient for creating 3D text. 28. Support setting the selected color and border thickness, mouse highlight color, shadow type, various helper display hidden, filter effect, weather effect. -## user's guidance +## Development Requirements -**This project only supports Windows system, .Net Framework 4.7.2 and newer version need to be installed on the computer.** +**These requirements are only required for development and compilation, and the operating environment does not require any software other than MongoDB and browser.** -**Compatible with Firefox and Google Chrome, the latest version of Google Chrome is recommended.** +1. Windows, Linux, Mac, or any other that supports `golang` and` nodejs`. +2. Golang 1.14.2+ +3. NodeJS 14.1+ +4. gcc 9.3.0+ (you need to install `MinGW` on windows and add environment variables to ensure that `gcc` can be accessed through the command line). +5. git 2.25.1+ +6. MongoDB v3.6.8 + +7. VSCode 1.44.2+ +8. Chrome 81.0+ or ​​Firefox 75.0+ -1. Install `NodeJs`, in the outermost directory (the one with` README.md` file), execute the following command. +Note: Lower version may also be supported. Please install these development environments before compiling. + +## Download and compile + +1. Download the source code. ```bash -npm install -npm run build +git clone https://github.com/tengge1/ShadowEditor.git ``` -2. Download `MongoDB`, install and start the MongoDB service. The default port of the MongoDB service is 27017. - -MongoDB download address: https://www.mongodb.com/download-center/community - -You can download the zip version, and then execute the following command to install the service in the bin folder of MongoDB, pay attention to modify the path. +In China, `github` is extremely slow, you can use `gitee` instead. ```bash -mongod --dbpath = D:\mongodb\db --logpath=D:\mongodb\log\mongoDB.log --install --serviceName MongoDB -net start MongoDB +git clone https://gitee.com/tengge1/ShadowEditor.git ``` -3. Edit the file `ShadowEditor.Web / Web.config` and change` 27017` to the port of the MongoDB service on your computer. - -```xml - -``` - -4. Use `Visual Studio 2017` to open the project and generate` ShadowEditor.Web` project. - -5. Deploy `ShadowEditor.Web` on iis to access it in the browser. - -Note: To publish the website deployment, you need to add a layer of folders outside the Web directory to store resources that cannot be disclosed, such as logs and database backups. - -6. To compile the document, please install gitbook. +If you need the `C#` version, you can checkout the `C#` branch, but it is no longer maintained. ```bash -npm install -g gitbook-cli +git checkout -b csharp origin / v0.4.6-csharp ``` -Then switch to the `docs-dev` directory and install the gitbook plugin. +2. Download and install `VSCode` and `Go` extension. + +It is recommended to install the following extensions, but it is not essential. + +`Shader languages ​​support for VS Code`, `C/C++`, `ESLint`, `Go`, `TOML Language Support`. + +3. Chinese users can set `golang` and `nodejs` proxy. + +In China, since `golang.org` is inaccessible, `github.com` and `npmjs.com` are extremely slow, it is recommended to set golang and nodejs proxy. + +Windows system execute ```bash -gitbook install +.\scripts\set_go_proxy.bat +.\scripts\set_npm_proxy.bat ``` -Then switch to the superior directory and execute the following command to generate the document. +Linux system execute ```bash -npm run docs +./scripts/set_go_proxy.sh +./scripts/set_npm_proxy.sh ``` -## common problem +4. Install the development tools for `golang`, and helpful for development, such as intelligent. -1. Why are upload failures when uploading models? +Windows system execute -You need to compress the model map and other resources into a zip package, and the entry file cannot be nested in a folder. The server will decompress the uploaded zip package and put it in the `~/Upload/Model` file, and add a piece of data in the MongoDB `_Mesh` table. +```bash +.\scripts\install_develop.bat +``` + +Linux system execute + +```bash +./scripts/install_develop.sh +``` + +5. Install the third-party dependencies. + +Windows system execute + +```bash +.\scripts\install.bat +``` + +Linux system execute + +```bash +./scripts/install.sh +``` + +6. Compile the source. + +Windows system execute + +```bash +.\scripts\build.bat +``` + +Linux system execute + +```bash +./scripts/build.sh +``` + +The distribution is in the `build` folder. When publishing, just copy this folder. + +7. Launch the program. + +Windows system execute + +```bash +.\scripts\run.bat +``` + +Linux system execute + +```bash +./scripts/run.sh +``` + +Here is the output + +``` +2020/05/02 09:57:20 starting shadoweditor server on port: 2020 +``` + +Then, you can access via browser: http://localhost:2020 + +## Q & A + +1. Failed when upload models? + +You need to compress the model map and other resources into a zip package, and the entry file cannot be nested in a folder. The server will decompress the uploaded zip package and put it in the `./public/Upload/Model` file, and add a piece of data in the MongoDB `_Mesh` collection. 2. How to combine multiple models together? Basic geometry supports multiple levels of nesting. You can add a `group` (in the geometry menu), and then drag multiple models onto the `group` on the scene tree. -3. How to open the permission system? +3. How to enable authority system? -Open the `ShadowEditor.Web/Web.config` file and set `EnableAuthority` to `true`. The default administrator username is `admin` and the password is `123456`. +Open `config.toml` and set `authority.enabled` to `true`. The default administrator username is `admin` and the password is `123456`. -4. The front-end report `asm.js has been disabled because the script debugger is connected. Please disconnect the debugger to enable asm.js. `Error. +4. The front-end report `asm.js has been disabled because the script debugger is connected. Please disconnect the debugger to enable asm.js.` Error. **Complete error**: asm.js has been disabled because the script debugger is connected. Please disconnect the debugger to enable asm.js. ammo.js (1,1) SCRIPT1028: SCRIPT1028: Expected identifier, string or number ShadowEditor.js (3948,8) SCRIPT5009: 'Shadow' is not defined. -**Solution**: Tencent browser does not support `ammo.js` (WebAssembly) compiled with` Emscripten`, it is recommended to change to Google Chrome -5. The frontend report `404.0-Not Found The resource you are looking for has been deleted, renamed or temporarily unavailable.` Error. - -Possible reason 1: **iis does not open asp.net support.** - -Solution: - -1. Open the control panel, programs and functions, enable or disable Windows functions. -2. Check the `.NET Framework`. -3. Check Internet Information Services, World Wide Web services, application development functions, the following `.NET Extensibility`,` ASP.NET`, `ISAPI extension`,` ISAPI filter`, `application initialization`, and confirm . - -Possible reason 2: **The server is not compiled.** - -Solution: -Use `Visual Studio 2017` to open the project, right click on the `ShadowEditor.Web` project in the Solution Manager and select Rebuild. - -6. Upload model report `access to the path "C:\inetpub\wwwroot\Upload\Model\20200208192356\temp" was denied.` Error. - -Cause: The `Upload` folder does not have write permission. - -Solution: - -Right-click on the `Upload` folder and click Properties. Security tab, click Advanced, add. Select the subject, fill in Everyone, basic permissions, and select `Full Control`. - -7. No response after publishing the scene. - -a. Check if the pop-up window is blocked on the right side of the address bar of Google Chrome. -b. Open the developer tools and see if the `Console` or `Network` tab reports an error. -c. The released scene is in the `ShadowEditor.Web\temp` directory, and see if there are any. - -8. Upgrading the .net framework to 4.7.2 reports an error: Could not find the file `E:\github\ShadowEditor\ShadowEditor.Web\bin\roslyn\csc.exe` - -Solution: Clean up the solution and regenerate the solution. +**Solution**: Tencent browser does not support `ammo.js` (WebAssembly) compiled with `Emscripten`, it is recommended to use `Chrome` or `Firebox` instead. ## Related Links * Three.js official website: https://threejs.org/ * LOL model viewer: https://github.com/tengge1/lol-model-viewer -* Model download 1: https://sketchfab.com/3d-models?features=downloadable -* Model download 2: https://www.3dpunk.com/work/index.html?category=downloadable +* Model download1: https://sketchfab.com/3d-models?features=downloadable +* Model download2: https://www.3dpunk.com/work/index.html?category=downloadable \ No newline at end of file