//============================================================ public void UploadNormal(int vertexSize, byte[] data, int offset, int length) { int byteSize = sizeof(float) * vertexSize; var stream = new DataStream(length, true, true); stream.Write(data, offset, length); stream.Position = 0; _nativeDescription = new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = length, Usage = ResourceUsage.Default, }; _nativeD3dBuffer = new DxBuffer(_device.NativeAdapter, stream, _nativeDescription); stream.Dispose(); FVector <VertexBufferBinding> bindings = new FVector <VertexBufferBinding>(); bindings.Push(new VertexBufferBinding(_nativeD3dBuffer, byteSize, 0)); // Position 4 bindings.Push(new VertexBufferBinding(_nativeD3dBuffer, byteSize, 16)); // Coord 2 bindings.Push(new VertexBufferBinding(_nativeD3dBuffer, byteSize, 24)); // Normal 4 _nativeBuffers = bindings.ToArray(); }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadWeightConfig(FXmlNode config) { // 读取权重信息 foreach (FXmlNode node in config.Nodes) { if (node.IsName("Bone")) { FDrVertexWeight weight = new FDrVertexWeight(); weight.LoadConfig(node); _weights.Push(weight); } } // 排序权重内容 if (!_weights.IsEmpty) { _weights.Sort(FDrVertexWeight.Comparer); if (_weights.Count > _maxWeightCount) { float total = 0; for (int n = 0; n < _maxWeightCount; n++) { total += _weights[n].Weight; } for (int n = 0; n < _maxWeightCount; n++) { FDrVertexWeight weight = _weights[n]; weight.Weight = weight.Weight / total; } } } }
//============================================================ public override void Setup() { base.Setup(); FVector <InputElement> elements = new FVector <InputElement>(); elements.Push(new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0)); elements.Push(new InputElement("COORD", 0, Format.R32G32_Float, 16, 0)); _nativeInputLayout = new InputLayout(_device.NativeAdapter, _nativePass.Description.Signature, elements.ToArray()); }
//============================================================ public void LoadFrameListConfig(FXmlNode config) { foreach (FXmlNode node in config.Nodes) { if (node.IsName("Frame")) { FDrFrame frame = new FDrFrame(); frame.LoadModelConfig(node); _frameList.Push(frame); } } }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadModelConfig(FXmlNode config) { // 获得属性内容 _frameCount = config.GetInteger("frame_count"); _frameTick = config.GetInteger("frame_tick"); _frameStart = config.GetInteger("frame_start"); _frameEnd = config.GetInteger("frame_end"); // 获得跟踪列表 foreach (FXmlNode node in config.Nodes) { if (node.IsName("Track")) { // 加载跟踪 FDrTrack track = new FDrTrack(_model); track.LoadModelConfig(node); _tracks.Push(track); // 判断是否为关联器 if (track.Bone.Name.StartsWith("jn_")) { FDrJoiner joiner = new FDrJoiner(_model); joiner.Name = track.Bone.Name; joiner.Track = track; _joiners.Push(joiner); } } } // 根据内容排序 _tracks.Sort(new FDrTrack(_model)); }
//============================================================ // <T>序列化内部数据到输出流。</T> // // @param output 输出流 //============================================================ public override void Serialize(IOutput output) { // 查找材质 FVector <FDrMaterial> materials = new FVector <FDrMaterial>(); foreach (FDrMaterialGroup group in RContent3dManager.MaterialConsole.Materials.Values) { FDrMaterial material = group.FindMaterial(_name); if (material != null) { material = new FDrMaterial(); material.Assign(group.Materials.First); material.Group = group; material.ThemeName = _name; group.Materials.Push(material); } if (material != null) { materials.Push(material); } } // 输出材质集合 output.WriteInt32(materials.Count); foreach (FDrMaterial material in materials) { material.SerializeAll(output); } }
//============================================================= public FVector <string> toInsertSql() { FVector <string> sqls = new FVector <string>(); foreach (FXlsRow row in _rows) { string names = null; string values = null; foreach (FXlsColumn colum in _columns.Values) { string name = colum.Name; names += name; string value = row.Get(name); if ("" == value) { values += "'" + '1' + "'"; } else { values += "'" + value + "'"; } if (colum.Index == _columns.Count) { break; } names += ","; values += ","; } string sql = "insert into pp (" + names + ")" + "values(" + values + ")"; sqls.Push(sql); } return(sqls); }
private void Update() { if (screenType == ScreenTypeEnum.Mobile && MLHands.IsStarted) { handCenter.Push(MLHands.Left.Center); transform.position = handCenter.Value; } if (IsPointerInRange && screenType == ScreenTypeEnum.Static) { //show position on 2d screen var worldPoint = AppController.Instance.PinchPoint.Value; var localPoint = transform.InverseTransformPoint(worldPoint); string x = Mathf.Abs(localPoint.x - 0.5f).ToString("0.000"); string y = Mathf.Abs(localPoint.y - 0.5f).ToString("0.000"); SocketClient.Instance.Send("mouse|" + x + "|" + y); } if (SocketClient.Instance.IsNewMessage) { if (SocketClient.Instance.Sender == ScreenId || contentType == ContentType.Model) { if (expectingImageData && requestPending) { spawnImage(SocketClient.Instance.LastMessage); } else if (SocketClient.Instance.LastMessage.StartsWith("media")) { var tokens = SocketClient.Instance.LastMessage.Split('|'); mediaType = tokens[1]; switch (mediaType) { case "img": expectingImageData = true; break; case "model": modelId = tokens[2]; SocketClient.log("Screen's got a new model " + modelId); break; case "null": //We didnt get anything so bail if (requestPending) { requestPending = false; GameObject nullObject = null; mediaRequestor.SendMessage("mediaReady", nullObject); } break; } } } } }
//============================================================ // <T>查找指定主题的材质。</T> //============================================================ public FDrMaterial SyncMaterial(string themeName) { string themeCode = RDrUtil.FormatPathToCode(themeName); foreach (FDrMaterial material in _materials) { if (material.ThemeCode == themeCode) { return(material); } } FDrMaterial createMaterial = new FDrMaterial(); createMaterial.Group = this; createMaterial.Assign(_materials.First); createMaterial.ThemeName = themeName; _materials.Push(createMaterial); _materials.Sort(new FDrMaterial()); return(createMaterial); }
//============================================================ public void DataUnserialize(IInput input) { // 读取顶点坐标 int count = input.ReadInt32(); for (int n = 0; n < count; n++) { FDrChannelFace face = new FDrChannelFace(); face.DataUnserialize(input); _indexs.Push(face); } }
//============================================================ // <T>根据模块名称和几何体名称,获得渲染对象。</T> // // @param modelName 模块名称 // @param geometryName 几何体名称 // @return 渲染对象 //============================================================ public FDrTemplateRenderable SyncRenderable(string modelName, string geometryName) { // 查询渲染对象 if (!_renderables.IsEmpty) { foreach (FDrTemplateRenderable renderable in _renderables) { if (renderable.ModelName.Equals(modelName) && renderable.GeometryName.Equals(geometryName)) { return(renderable); } } } // 新建渲染对象 FDrTemplateRenderable newRenderable = new FDrTemplateRenderable(); newRenderable.ModelName = modelName; newRenderable.GeometryName = geometryName; _renderables.Push(newRenderable); return(newRenderable); }
//============================================================ // <T>启动任务控制台。<T> //============================================================ public void Start() { // 创建所有线程 for (int n = 0; n < _threadCount; n++) { FTaskThread thread = new FTaskThread(); thread.Console = this; _threads.Push(thread); } // 启动所有线程 for (int n = 0; n < _threadCount; n++) { _threads[n].Start(); } }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode xconfig) { _optionLoaded = xconfig.GetInteger("option_loaded", EDrFlag.Inherit); _optionSelect = xconfig.GetInteger("option_select", EDrFlag.Inherit); _optionGround = xconfig.GetInteger("option_ground", EDrFlag.Inherit); if (xconfig.Contains("option_merge")) { _optionMergeVertex = xconfig.GetInteger("option_merge"); } if (xconfig.Contains("option_merge_vertex")) { _optionMergeVertex = xconfig.GetInteger("option_merge_vertex"); } _optionMergeMaterial = xconfig.GetInteger("option_merge_material", EDrFlag.Inherit); _optionLightMap = xconfig.GetInteger("option_light_map", EDrFlag.Inherit); //............................................................ //............................................................ // 加载引用列表 FXmlNode xreferences = xconfig.Find("References"); if (null != xreferences) { foreach (FXmlNode xreference in xreferences.Nodes) { if (xreference.IsName("Reference")) { FDrTemplateReference reference = new FDrTemplateReference(); reference.LoadConfig(xreference); _references.Push(reference); } } } //............................................................ // 加载动画列表 FXmlNode xanimation = xconfig.Find("Animation"); if (null != xanimation) { _animation.Model = _model; _animation.LoadConfig(xanimation); } //............................................................ // 材质集合排序 if (!_materials.IsEmpty) { _materials.Sort(_materials.First); } }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode xconfig) { // 加载编号 _id = xconfig.GetInteger("id"); // 加载名称 _name = xconfig.Get("name"); // 加载层数 _layerCount = xconfig.GetInteger("layer_count"); // 加载尺寸 _size.Parse(xconfig.Get("size")); // 加载切割尺寸 _range.Parse(xconfig.Get("range")); // 加载深度 _deep = xconfig.GetFloat("deep"); _incise = RInt.Parse(xconfig.GetFloat("deep")); //............................................................ // 加载高度纹理 FXmlNode xheight = xconfig.Find("Height"); if (null != xheight) { _textureHeight = xheight.Get("source"); } // 加载颜色纹理 FXmlNode xcolor = xconfig.Find("Color"); if (null != xcolor) { _textureColor = xcolor.Get("source"); } //............................................................ // 加载层信息 FXmlNode xlayers = xconfig.Find("Layers"); if (null != xlayers) { foreach (FXmlNode xlayer in xlayers.Nodes) { FDrMapLayer layer = new FDrMapLayer(); layer.Index = _layers.Count; layer.LoadConfig(xlayer); _layers.Push(layer); } } }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadModelConfig(FXmlNode config) { // 读取基本属性 _id = config.GetInteger("bone_id"); _name = config.Get("name"); _model.Skeleton.Bones.Set(_id, this); // 读取子节点 foreach (FXmlNode node in config.Nodes) { if (node.IsName("Bone")) { FDrBone bone = new FDrBone(_model); bone.LoadModelConfig(node); _children.Push(bone); } } }
//============================================================ // <T>获得任务集合。</T> // // @return 任务集合 //============================================================ public FVector <ITask> FetchTasks(int count) { FVector <ITask> tasks = null; lock (_tasks) { tasks = new FVector <ITask>(count); int n = 0; foreach (ITask task in _tasks) { n++; tasks.Push(task); if (n > count) { break; } } } return(tasks); }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadModelConfig(FXmlNode xconfig) { // 读取根骨骼 foreach (FXmlNode node in xconfig.Nodes) { if (node.IsName("Bone")) { FDrBone bone = new FDrBone(_model); bone.LoadModelConfig(node); _roots.Push(bone); } } // 调整骨骼编号 int count = _bones.Count; for (int n = 0; n < count; n++) { FDrBone bone = _bones.Value(n); _adjustBones.Push(bone); bone.AdjustId = n; } }
private void Update() { bool isPinching = fhand.KeyPose == MLHandKeyPose.Pinch; isPinchHandled = false; isPinchStart = isPinching && !wasPinching; isPinchEnd = !isPinching && wasPinching; var pinchPoint = Vector3.Lerp(mlhand.Index.Tip.Position, mlhand.Thumb.Tip.Position, 0.5f); if (isPinchStart) { PinchPoint.Value = Vector3.Lerp(mlhand.Index.Tip.Position, mlhand.Thumb.Tip.Position, 0.5f); } PinchPoint.Push(pinchPoint); PinchPointer.position = PinchPoint.Value; if (SocketClient.Instance.IsNewMessage) { if (SocketClient.Instance.LastMessage.StartsWith("enroll")) { var tokens = SocketClient.Instance.LastMessage.Split('|'); var screenType = tokens[1]; var contentType = tokens[2]; var newScreen = Instantiate <GameObject>(ScreenPrefab); newScreen.GetComponent <Screen>().SetParams(SocketClient.Instance.Sender, screenType, contentType); } else if (SocketClient.Instance.LastMessage == "reset") { Reset(); } } wasPinching = isPinching; }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode config) { foreach (FXmlNode node in config.Nodes) { if (node.IsName("Frames")) { foreach (FXmlNode xframe in node.Nodes) { if (xframe.IsName("Frame")) { FDrFrameInfo frame = new FDrFrameInfo(); frame.LoadConfig(xframe); _frameInfos.Push(frame); } } } else if (node.IsName("Movie")) { FDrMovie movie = new FDrMovie(); movie.LoadConfig(node); _movies.Push(movie); } } }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode xconfig) { _optionLoaded = xconfig.GetInteger("option_loaded", EDrFlag.Inherit); _optionSelect = xconfig.GetInteger("option_select", EDrFlag.Inherit); _optionGround = xconfig.GetInteger("option_ground", EDrFlag.Inherit); if (xconfig.Contains("option_merge")) { _optionMergeVertex = xconfig.GetInteger("option_merge"); } if (xconfig.Contains("option_merge_vertex")) { _optionMergeVertex = xconfig.GetInteger("option_merge_vertex"); } _optionMergeMaterial = xconfig.GetInteger("option_merge_material", EDrFlag.Inherit); _optionLightMap = xconfig.GetInteger("option_light_map", EDrFlag.Inherit); //............................................................ // 加载渲染列表 FXmlNode xrenderables = xconfig.Find("Renderables"); if (null != xrenderables) { _outline.InitializeMin(); foreach (FXmlNode xrenderable in xrenderables.Nodes) { if (xrenderable.IsName("Renderable")) { // 建立渲染对象 FDrTemplateRenderable renderable = new FDrTemplateRenderable(); renderable.Template = this; renderable.LoadConfig(xrenderable); if (null == _model) { _model = renderable.Model; } _outline.InnerMax(renderable.Outline); // 设置材质 FDrMaterialGroup material = renderable.Material; if (null == material) { RMoCore.TrackConsole.Write(this, "LoadConfig", "Material is not exists. (template={0}, geometry={1}, material={2})", _name, renderable.GeometryName, renderable.MaterialName); return; } if (!_materials.Contains(material)) { _materials.Push(material); } _renderables.Push(renderable); } } } //............................................................ // 加载引用列表 FXmlNode xreferences = xconfig.Find("References"); if (null != xreferences) { foreach (FXmlNode xreference in xreferences.Nodes) { if (xreference.IsName("Reference")) { FDrTemplateReference reference = new FDrTemplateReference(); reference.LoadConfig(xreference); _references.Push(reference); } } } //............................................................ // 加载动画列表 FXmlNode xanimation = xconfig.Find("Animation"); if (null != xanimation) { _animation.Model = _model; _animation.LoadConfig(xanimation); } //............................................................ // 材质集合排序 if (!_materials.IsEmpty) { _materials.Sort(_materials.First); } }
void Update() { if (!MLHands.IsStarted) { return; } if (!hand.Index.Tip.IsValid || !hand.Thumb.Tip.IsValid) { return; } if (hand.KeyPose == MLHandKeyPose.NoHand) { return; } bool isActive = fhand.KeyPose == MLHandKeyPose.Pinch || fhand.KeyPose == MLHandKeyPose.Fist || fhand.KeyPose == MLHandKeyPose.Ok; indexTip.Push(hand.Index.Tip.Position); thumbTip.Push(hand.Thumb.Tip.Position); if (isActive) { var pinchDistance = Vector3.Distance(indexTip.Value, thumbTip.Value); if (pinchDistance > 0.2) { isActive = false; } } if (isActive && !wasActive) { //Pinch start CursorRenderer.material = ActiveMaterial; if (CursorActivated != null) { CursorActivated(this, new CursorEventArgs() { Sender = null, Cursor = this }); } } else if (wasActive && !isActive) { //Pinch end CursorRenderer.material = InactiveMaterial; if (CursorDeactivated != null) { CursorDeactivated(this, new CursorEventArgs()); } } var pinchPoint = Vector3.Lerp(indexTip.Value, thumbTip.Value, 0.5f); if (!isActive) { RaycastHit hitInfo; if (Physics.Raycast(new Ray(Camera.main.transform.position, pinchPoint - Camera.main.transform.position), out hitInfo, 100, uiMask)) { Cursor.transform.position = hitInfo.point; eyeToItemDistance = hitInfo.distance; pinchToItemDistance = Vector3.Distance(hitInfo.point, pinchPoint); eyeToPinchDistance = Vector3.Distance(Camera.main.transform.position, pinchPoint); } else { Cursor.transform.position = pinchPoint; pinchToItemDistance = 0; } } else { var v = (pinchPoint - Camera.main.transform.position).normalized; Cursor.transform.position = pinchPoint + v * pinchToItemDistance; } PinchPointObject.position = pinchPoint; wasActive = isActive; }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode xconfig) { // 读取属性 _effectName = xconfig.Nvl("effect_name"); _transformName = xconfig.Nvl("transform_name"); _optionLight = xconfig.GetInteger("option_light", _optionLight); _optionMerge = xconfig.GetInteger("option_merge", _optionMerge); _optionSort = xconfig.GetInteger("option_sort", _optionSort); _sortLevel = xconfig.GetInteger("sort_level", _sortLevel); _optionAlpha = xconfig.GetInteger("option_alpha", _optionAlpha); _optionDepth = xconfig.GetInteger("option_depth", _optionDepth); _optionCompare = xconfig.Get("option_compare", _optionCompare); _optionDouble = xconfig.GetInteger("option_double", _optionDouble); _optionShadow = xconfig.GetInteger("option_shadow", _optionShadow); _optionShadowSelf = xconfig.GetInteger("option_shadow_self", _optionShadowSelf); _optionDynamic = xconfig.GetInteger("option_dynamic", _optionDynamic); _optionTransmittance = xconfig.GetInteger("option_transmittance", _optionTransmittance); _optionOpacity = xconfig.GetInteger("option_opacity", _optionOpacity); // 查找节点 FXmlNode xmaterialConfig = null; FXmlNode xmaterials = xconfig.Find("Materials"); FXmlNode xtextures = xconfig.Find("Textures"); // 读取纹理列表 if (null == xmaterials) { FXmlNode xmaterial = xconfig.Find("Material"); if (null != xmaterial) { FDrMaterial material = new FDrMaterial(); material.Group = this; material.LoadConfig(xmaterial); _materials.Push(material); // 查找纹理节点 xtextures = xmaterial.Find("Textures"); xmaterialConfig = xmaterial; } } else { // 找到默认节点 FXmlNode xdefault = null; foreach (FXmlNode xmaterial in xmaterials.Nodes) { if (xmaterial.IsName("Material")) { string themeCode = RDrUtil.FormatPathToCode(xmaterial.Get("theme_name")); xdefault = xmaterial; xmaterialConfig = xmaterial; if ("shadow" == themeCode) { break; } } } foreach (FDrTheme theme in RContent3dManager.ThemeConsole.Themes.Values) { string code = theme.Code; // 查找加载信息 bool finded = false; foreach (FXmlNode xmaterial in xmaterials.Nodes) { if (xmaterial.IsName("Material")) { string themeCode = RDrUtil.FormatPathToCode(xmaterial.Get("theme_name")); if (code == themeCode) { FDrMaterial material = new FDrMaterial(); material.Group = this; material.LoadConfig(xmaterial); FDrMaterial findMaterial = FindMaterial(material.ThemeName); if (null == findMaterial) { _materials.Push(material); } finded = true; break; } } } // 如果不存在,则新建材质 if (!finded) { if (null != xdefault) { FDrMaterial material = new FDrMaterial(); material.Group = this; material.LoadConfig(xdefault); material.Theme = theme; material.ThemeName = theme.Name; _materials.Push(material); } } } } // 如果效果名称不存在,则获得首个材质设定 if (!xconfig.Contains("effect_name") && (null != xmaterialConfig)) { _effectName = xmaterialConfig.Nvl("effect_name"); _transformName = xmaterialConfig.Nvl("transform_name"); _optionLight = xmaterialConfig.GetInteger("option_light", _optionLight); _optionMerge = xmaterialConfig.GetInteger("option_merge", _optionMerge); _optionSort = xmaterialConfig.GetInteger("option_sort", _optionSort); _sortLevel = xmaterialConfig.GetInteger("sort_level", _sortLevel); _optionAlpha = xmaterialConfig.GetInteger("option_alpha", _optionAlpha); _optionDepth = xmaterialConfig.GetInteger("option_depth", _optionDepth); _optionCompare = xmaterialConfig.Get("option_compare", _optionCompare); _optionDouble = xmaterialConfig.GetInteger("option_double", _optionDouble); _optionShadow = xmaterialConfig.GetInteger("option_shadow", _optionShadow); _optionShadowSelf = xmaterialConfig.GetInteger("option_shadow_self", _optionShadowSelf); _optionDynamic = xmaterialConfig.GetInteger("option_dynamic", _optionDynamic); _optionTransmittance = xmaterialConfig.GetInteger("option_transmittance", _optionTransmittance); _optionOpacity = xmaterialConfig.GetInteger("option_opacity", _optionOpacity); } foreach (FDrMaterial material in _materials) { material.LoadGroup(this); } // 读取纹理列表 if (null != xtextures) { foreach (FXmlNode xtexture in xtextures.Nodes) { if (xtexture.IsName("Texture")) { FDrMaterialTexture materialTexture = new FDrMaterialTexture(); materialTexture.Material = this; materialTexture.LoadConfig(xtexture); FDrTexture texture = RContent3dManager.TextureConsole.Find(materialTexture.Source); if (null != texture) { materialTexture.Texture = texture; materialTexture.IsValid = true; } else { RMoCore.TrackConsole.Write(this, "LoadConfig", "Texture is not exists in material. (texture={0}, file_name={1})", materialTexture.Source, _configFileName); materialTexture.IsValid = false; } _textures.Push(materialTexture); } } } }