-- print("Деревьев: ",xix)

	local primary = model.PrimaryPart
	local primaryCf = primary.CFrame	
	for _,v in pairs(model:GetDescendants()) do
		if (v:IsA("BasePart")) then
			v.Size = (v.Size * scale)
			if (v ~= primary) then
				v.CFrame = (primaryCf + (primaryCf:inverse() * v.Position * scale))
			end
		end
	end	
	return model
end
local function spawnTree(pos)
	if rnd:NextInteger(1,10000) <= TREE_SCALE*100 then
		-- сажаем
		local mm=rnd:NextInteger(1,#tree)
		
		local co=tree[mm]
		local ct=co:Clone()
		ct=ScaleModel(ct,rnd:NextNumber(0.5,2))-- изменение размеров
		ct.Parent = game.Workspace.Tree
		ct.Name = "Tree " .. tostring(ct)
		
		local cx=pos.X
		local cz=pos.Z
		local cy=pos.y
		
		ct:SetPrimaryPartCFrame(CFrame.new(cx, cy + ct.PrimaryPart.Size.Y*0.5, cz)) -- переместить
		ct:SetPrimaryPartCFrame(ct:GetPrimaryPartCFrame() * CFrame.Angles(0, rnd:NextInteger(0,360), 0)) -- повернуть
	end 
end


local chunks = {}

local function chunkExists(chunkX, chunkZ)
	if not chunks[chunkX] then
		chunks[chunkX] = {}
	end
	return chunks[chunkX][chunkZ]
end
